mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-09 15:10:18 +00:00
Replace strtok
with strtok_r
This commit is contained in:
parent
6a74b3f487
commit
fb00990bab
1 changed files with 4 additions and 3 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue