mirror of https://github.com/kiwix/libkiwix.git
Fix computeAbsolutePath.
Correctly delete the duplicated string. Use strtok_r to be thread safe.
This commit is contained in:
parent
44bec86f31
commit
52299ef767
|
@ -121,22 +121,24 @@ std::string computeAbsolutePath(const std::string& path, const std::string& rela
|
||||||
#else
|
#else
|
||||||
char* cRelativePath = strdup(relativePath.c_str());
|
char* cRelativePath = strdup(relativePath.c_str());
|
||||||
#endif
|
#endif
|
||||||
char* token = strtok(cRelativePath, "/");
|
char* saveptr = nullptr;
|
||||||
|
char* token = strtok_r(cRelativePath, "/", &saveptr);
|
||||||
|
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if (std::string(token) == "..") {
|
if (std::string(token) == "..") {
|
||||||
absolutePath = removeLastPathElement(absolutePath, true, false);
|
absolutePath = removeLastPathElement(absolutePath, true, false);
|
||||||
token = strtok(NULL, "/");
|
token = strtok_r(NULL, "/", &saveptr);
|
||||||
} else if (strcmp(token, ".") && strcmp(token, "")) {
|
} else if (strcmp(token, ".") && strcmp(token, "")) {
|
||||||
absolutePath += std::string(token);
|
absolutePath += std::string(token);
|
||||||
token = strtok(NULL, "/");
|
token = strtok_r(NULL, "/", &saveptr);
|
||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
absolutePath += SEPARATOR;
|
absolutePath += SEPARATOR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = strtok(NULL, "/");
|
token = strtok_r(NULL, "/", &saveptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(cRelativePath);
|
||||||
|
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue