From 52299ef767ee52e48c834909b1be6e41d12182a9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Sun, 11 Aug 2019 15:25:00 +0200 Subject: [PATCH] Fix computeAbsolutePath. Correctly delete the duplicated string. Use strtok_r to be thread safe. --- src/tools/pathTools.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tools/pathTools.cpp b/src/tools/pathTools.cpp index c48784e7..07eb3d4d 100644 --- a/src/tools/pathTools.cpp +++ b/src/tools/pathTools.cpp @@ -121,22 +121,24 @@ std::string computeAbsolutePath(const std::string& path, const std::string& rela #else char* cRelativePath = strdup(relativePath.c_str()); #endif - char* token = strtok(cRelativePath, "/"); + char* saveptr = nullptr; + char* token = strtok_r(cRelativePath, "/", &saveptr); while (token != NULL) { if (std::string(token) == "..") { absolutePath = removeLastPathElement(absolutePath, true, false); - token = strtok(NULL, "/"); + token = strtok_r(NULL, "/", &saveptr); } else if (strcmp(token, ".") && strcmp(token, "")) { absolutePath += std::string(token); - token = strtok(NULL, "/"); + token = strtok_r(NULL, "/", &saveptr); if (token != NULL) { absolutePath += SEPARATOR; } } else { - token = strtok(NULL, "/"); + token = strtok_r(NULL, "/", &saveptr); } } + free(cRelativePath); return absolutePath; }