mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-20 06:36:16 +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:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user