git repos / PlatformFolders

commit 2a74df65

Poul Sander · 2019-02-13 16:51
2a74df65a39671c738b871f8af98f7580708992d patch · browse files
parent df5fd138b04b4f8511531a1062c34f33879e278e

Make appendExtraFoldersTokenizer thread safe

Changed files

M sago/platform_folders.cpp before
diff --git a/sago/platform_folders.cpp b/sago/platform_folders.cpp index cb863f3..bb9f621 100644 --- a/sago/platform_folders.cpp +++ b/sago/platform_folders.cpp
@@ -137,6 +137,7 @@ static std::string GetAppDataLocal() {
#include <sys/types.h>
// For strlen and strtok
#include <cstring>
+#include <sstream>
//Typically Linux. For easy reading the comments will just say Linux but should work with most *nixes
static void throwOnRelative(const char* envName, const char* envValue) {
@@ -177,18 +178,17 @@ namespace sago {
#if !defined(_WIN32) && !defined(__APPLE__)
namespace internal {
void appendExtraFoldersTokenizer(const char* envName, const char* envValue, std::vector<std::string>& folders) {
- std::vector<char> buffer(envValue, envValue + std::strlen(envValue) + 1);
- char* p = std::strtok ( &buffer[0], ":");
- while (p != nullptr) {
- if (p[0] == '/') {
- folders.push_back(p);
+ std::stringstream ss = std::stringstream(envValue);
+ std::string value;
+ while (std::getline(ss, value, ':')) {
+ if (value[0] == '/') {
+ folders.push_back(value);
}
else {
//Unless the system is wrongly configured this should never happen... But of course some systems will be incorectly configured.
//The XDG documentation indicates that the folder should be ignored but that the program should continue.
- std::cerr << "Skipping path \"" << p << "\" in \"" << envName << "\" because it does not start with a \"/\"\n";
+ std::cerr << "Skipping path \"" << value << "\" in \"" << envName << "\" because it does not start with a \"/\"\n";
}
- p = std::strtok (nullptr, ":");
}
}
}