From 2232b60430c8ea3a994c6f0ea18b3bee44e726ac Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 28 Nov 2013 21:17:17 +0100 Subject: [PATCH] Fixed possible segfault caused by use of static string. --- tests/testRunner.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/testRunner.cpp b/tests/testRunner.cpp index 3286e23a..48a09d17 100644 --- a/tests/testRunner.cpp +++ b/tests/testRunner.cpp @@ -217,10 +217,11 @@ const std::string getFileNameFromPath(const std::string& path) } +static char g_moduleNameBuffer[2048]; + + const char* getTestModuleNameFromSourceFile(const char *path_) { - static std::string moduleName; - static const std::string testRunnerPath(getNormalizedPath(__FILE__)); static const std::string testRunnerFileName(getFileNameFromPath(testRunnerPath)); @@ -235,9 +236,11 @@ const char* getTestModuleNameFromSourceFile(const char *path_) const std::string testPath(path.begin() + basePath.length(), path.end()); // "module/testFile.cpp" --> "module" - moduleName = testPath.substr(0, testPath.length() - testFileName.length() - 1); + const std::string moduleName(testPath.substr(0, testPath.length() - testFileName.length() - 1)); + std::copy(moduleName.begin(), moduleName.end(), g_moduleNameBuffer); + g_moduleNameBuffer[moduleName.length()] = 0; - return moduleName.c_str(); + return g_moduleNameBuffer; }