From fb00990bab775d0a0b867d0c0c95253313a10eae Mon Sep 17 00:00:00 2001 From: Samuel Gomes <47574584+a740g@users.noreply.github.com> Date: Mon, 24 Oct 2022 02:09:55 +0530 Subject: [PATCH] Replace `strtok` with `strtok_r` --- internal/c/parts/gui/gui.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/c/parts/gui/gui.cpp b/internal/c/parts/gui/gui.cpp index 9a4f483a1..f26bea26e 100644 --- a/internal/c/parts/gui/gui.cpp +++ b/internal/c/parts/gui/gui.cpp @@ -36,12 +36,13 @@ /// @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() 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; char **result = (char **)malloc(capacity * sizeof(*result)); + char *saveptr; (*count) = 0; // Set count to zero - auto tok = strtok(str, "|"); + auto tok = strtok_r(str, "|", &saveptr); for (;;) { if ((*count) >= capacity) @@ -52,7 +53,7 @@ static char **gui_tokenize(const char *input, int32_t *count) { if (!tok) break; - tok = strtok(nullptr, "|"); + tok = strtok_r(nullptr, "|", &saveptr); } free(str);