1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-08-05 03:00:25 +00:00

Replace strtok with strtok_r

This commit is contained in:
Samuel Gomes 2022-10-24 02:09:55 +05:30
parent 6a74b3f487
commit fb00990bab

View file

@ -36,12 +36,13 @@
/// @param count Point to an integer that will hold the count of tokens. This cannot be NULL /// @param count Point to an integer that will hold the count of tokens. This cannot be NULL
/// @return Array of string tokens. This must be freed using gui_free_tokens() /// @return Array of string tokens. This must be freed using gui_free_tokens()
static char **gui_tokenize(const char *input, int32_t *count) { static char **gui_tokenize(const char *input, int32_t *count) {
auto str = strdup(input); // since strtok() modifys the string auto str = strdup(input);
auto capacity = 2; auto capacity = 2;
char **result = (char **)malloc(capacity * sizeof(*result)); char **result = (char **)malloc(capacity * sizeof(*result));
char *saveptr;
(*count) = 0; // Set count to zero (*count) = 0; // Set count to zero
auto tok = strtok(str, "|"); auto tok = strtok_r(str, "|", &saveptr);
for (;;) { for (;;) {
if ((*count) >= capacity) if ((*count) >= capacity)
@ -52,7 +53,7 @@ static char **gui_tokenize(const char *input, int32_t *count) {
if (!tok) if (!tok)
break; break;
tok = strtok(nullptr, "|"); tok = strtok_r(nullptr, "|", &saveptr);
} }
free(str); free(str);