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:
Andreas Kling 2020-11-14 11:24:42 +01:00
parent a65e7db533
commit f568aed2e7
Notes: sideshowbarker 2024-07-19 02:28:34 +09:00

View file

@ -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];
}