From 0ab009e17acb97c4304756a9f4b0377b10ecc96b Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Sun, 11 Sep 2016 13:17:52 +0200 Subject: [PATCH] Workaround for off-by-one error in whereami library --- src/platformTools.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platformTools.cpp b/src/platformTools.cpp index 6093f42..2dcda5a 100644 --- a/src/platformTools.cpp +++ b/src/platformTools.cpp @@ -19,13 +19,16 @@ path getBinPath() { } // Get path - std::vector 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 buffer(pathLength + 1); if (wai_getExecutablePath(buffer.data(), buffer.size(), nullptr) == -1) { throw std::runtime_error("Error reading path."); } + buffer[pathLength] = 0; // Convert to boost::filesystem::path - string pathString(buffer.data(), buffer.size()); + string pathString(buffer.data()); static path binPath(boost::filesystem::canonical(pathString).make_preferred()); return binPath; } catch (...) {