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
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue