From 58b2c1ec9ca9096a7e04a729bb222363fd021ee7 Mon Sep 17 00:00:00 2001 From: Wenkai Du <43822138+wenkaidu@users.noreply.github.com> Date: Fri, 15 Apr 2022 14:32:11 -0700 Subject: [PATCH] Fix random segfault (#537) [ROCm/rccl commit: fd2f1b3b885a5512b372f1190d061c9cb47be387] --- projects/rccl/src/graph/rome_models.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/projects/rccl/src/graph/rome_models.cc b/projects/rccl/src/graph/rome_models.cc index 8ac7de67ca..4b5325060a 100644 --- a/projects/rccl/src/graph/rome_models.cc +++ b/projects/rccl/src/graph/rome_models.cc @@ -690,10 +690,11 @@ static void parseOptions(struct ncclTopoSystem* system, const char *options) { strcpy(str_temp, options); char* tokens[MAX_OPT_TOKENS]; int numTokens = 0; - tokens[numTokens] = strtok(str_temp, "=, "); + char* state; + tokens[numTokens] = strtok_r(str_temp, "=, ", &state); numTokens++; while (tokens[numTokens-1] != NULL && numTokens < MAX_OPT_TOKENS) - tokens[numTokens++] = strtok(NULL, "=, "); + tokens[numTokens++] = strtok_r(NULL, "=, ", &state); for (int i = 0; i < numTokens/2; i++) { if (strcmp(tokens[i*2], "netGdrLevel") == 0) { int j; @@ -725,10 +726,11 @@ static bool disableNumaMatching(const char *options) { strcpy(str_temp, options); char* tokens[MAX_OPT_TOKENS]; int numTokens = 0; - tokens[numTokens] = strtok(str_temp, "=, "); + char* state; + tokens[numTokens] = strtok_r(str_temp, "=, ", &state); numTokens++; while (tokens[numTokens-1] != NULL && numTokens < MAX_OPT_TOKENS) - tokens[numTokens++] = strtok(NULL, "=, "); + tokens[numTokens++] = strtok_r(NULL, "=, ", &state); for (int i = 0; i < numTokens/2; i++) { if (strcmp(tokens[i*2], "disableNumaMatching") == 0) { return (bool)atol(tokens[i*2+1]);