From: Joel Rosdahl Date: Sat, 14 Aug 2010 19:19:32 +0000 (+0200) Subject: Use reentrant strtok_r() instead of strtok() X-Git-Tag: v3.1~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff2089c914d17b5c153e5e5cc1de1e2a0f8a71e8;p=thirdparty%2Fccache.git Use reentrant strtok_r() instead of strtok() --- diff --git a/args.c b/args.c index 23819046a..ae5ec9694 100644 --- a/args.c +++ b/args.c @@ -43,10 +43,10 @@ args_init_from_string(const char *command) struct args *args; char *p = x_strdup(command); char *q = p; - char *word; + char *word, *saveptr = NULL; args = args_init(0, NULL); - while ((word = strtok(q, " \t\r\n"))) { + while ((word = strtok_r(q, " \t\r\n", &saveptr))) { args_add(args, word); q = NULL; } diff --git a/ccache.c b/ccache.c index b27127fa7..2242fa3f3 100644 --- a/ccache.c +++ b/ccache.c @@ -944,10 +944,10 @@ calculate_common_hash(struct args *args, struct mdfour *hash) p = getenv("CCACHE_EXTRAFILES"); if (p) { - char *path, *q; + char *path, *q, *saveptr = NULL; p = x_strdup(p); q = p; - while ((path = strtok(q, PATH_DELIM))) { + while ((path = strtok_r(q, PATH_DELIM, &saveptr))) { cc_log("Hashing extra file %s", path); hash_delimiter(hash, "extrafile"); if (!hash_file(hash, path)) { @@ -1847,14 +1847,14 @@ static unsigned parse_sloppiness(char *p) { unsigned result = 0; - char *word, *q; + char *word, *q, *saveptr = NULL; if (!p) { return result; } p = x_strdup(p); q = p; - while ((word = strtok(q, ", "))) { + while ((word = strtok_r(q, ", ", &saveptr))) { if (str_eq(word, "file_macro")) { cc_log("Being sloppy about __FILE__"); result |= SLOPPY_FILE_MACRO; diff --git a/execute.c b/execute.c index a3a0894e9..45b1469c2 100644 --- a/execute.c +++ b/execute.c @@ -247,13 +247,15 @@ find_executable(const char *name, const char *exclude_name) static char * find_executable_in_path(const char *name, const char *exclude_name, char *path) { - char *tok; + char *tok, *saveptr = NULL; path = x_strdup(path); /* search the path looking for the first compiler of the right name that isn't us */ - for (tok = strtok(path, PATH_DELIM); tok; tok = strtok(NULL, PATH_DELIM)) { + for (tok = strtok_r(path, PATH_DELIM, &saveptr); + tok; + tok = strtok_r(NULL, PATH_DELIM, &saveptr)) { #ifdef _WIN32 char namebuf[MAX_PATH]; int ret = SearchPath(tok, name, ".exe", diff --git a/hashutil.c b/hashutil.c index 11c6cddad..1674c3a83 100644 --- a/hashutil.c +++ b/hashutil.c @@ -287,12 +287,12 @@ int hash_multicommand_output(struct mdfour *hash, const char *commands, const char *compiler) { - char *command_string, *command, *p; + char *command_string, *command, *p, *saveptr = NULL; int ok = 1; command_string = x_strdup(commands); p = command_string; - while ((command = strtok(p, ";"))) { + while ((command = strtok_r(p, ";", &saveptr))) { if (!hash_command_output(hash, command, compiler)) { ok = 0; }