Workaround for off-by-one error in whereami library
This commit is contained in:
parent
2607b9a12b
commit
0ab009e17a
|
@ -19,13 +19,16 @@ path getBinPath() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get path
|
// Get path
|
||||||
std::vector<char> buffer(pathLength);
|
// Note: According to documentation, pathLength does *not* include the trailing zero. Actually, it does.
|
||||||
|
// In case there are situations where it doesn't, we allocate one character more.
|
||||||
|
std::vector<char> buffer(pathLength + 1);
|
||||||
if (wai_getExecutablePath(buffer.data(), buffer.size(), nullptr) == -1) {
|
if (wai_getExecutablePath(buffer.data(), buffer.size(), nullptr) == -1) {
|
||||||
throw std::runtime_error("Error reading path.");
|
throw std::runtime_error("Error reading path.");
|
||||||
}
|
}
|
||||||
|
buffer[pathLength] = 0;
|
||||||
|
|
||||||
// Convert to boost::filesystem::path
|
// Convert to boost::filesystem::path
|
||||||
string pathString(buffer.data(), buffer.size());
|
string pathString(buffer.data());
|
||||||
static path binPath(boost::filesystem::canonical(pathString).make_preferred());
|
static path binPath(boost::filesystem::canonical(pathString).make_preferred());
|
||||||
return binPath;
|
return binPath;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
Loading…
Reference in New Issue