KDB_EXEC_PATH: Fix pointer after getenv
@@ -52,7 +52,13 @@ void tryExternalCommand (char ** argv)
{
std::vector<std::string> pathes;
- std::string execPath = getenv ("KDB_EXEC_PATH");
+ char * execPathPtr = getenv ("KDB_EXEC_PATH");
+ if (execPathPtr)
+ {
+ // The string pointed by the pointer returned by getenv shall
+ // not be modified. The constructor of std::string constructs a
+ // copy of the string.
+ std::string execPath (execPathPtr);
size_t pos = 0;
std::string token;
std::string delimiter = ":";
@@ -62,7 +68,9 @@ void tryExternalCommand (char ** argv)
pathes.push_back (token);
execPath.erase (0, pos + delimiter.length ());
}
+ // There is one last path in execPath after the while
pathes.push_back (execPath);
+ }
pathes.push_back (buildinExecPath);
for (auto & pathe : pathes)
