mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibC: strtok_r() should not go past the last token
When we hit the last token, make the saved pointer point to the null terminator instead of to the next token. This ensures that the next call to strtok_r() returns null as expected. Found by running GCC in UE. :^)
This commit is contained in:
parent
a65e7db533
commit
f568aed2e7
Notes:
sideshowbarker
2024-07-19 02:28:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f568aed2e76
|
@ -457,7 +457,11 @@ char* strtok_r(char* str, const char* delim, char** saved_str)
|
|||
return &str[token_start];
|
||||
}
|
||||
|
||||
*saved_str = &str[token_end + 1];
|
||||
if (str[token_end] == '\0')
|
||||
*saved_str = &str[token_end];
|
||||
else
|
||||
*saved_str = &str[token_end + 1];
|
||||
|
||||
str[token_end] = '\0';
|
||||
return &str[token_start];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue