reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 0c908bc93b745d3c806688be2467af2c27fad36b
parent effd0cc3d7bd97b376b3fc349a4d15b0610ba4b4
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun,  1 Nov 2020 07:44:16 -0500

path: fix truncated first character of top-level unix absolute paths [p=2359736]

It was due to an integer overflow. last = 1, and pos = string::npos. last + pos == 0 was true in the first two iterations.

Diffstat:
Msrc/path.cpp | 11+++++------
Mtest/path.cpp | 5+++++
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/path.cpp b/src/path.cpp @@ -50,7 +50,11 @@ static std::vector<std::string> Split(const std::string &input, int *attributes) while(last < input.size()) { const size_t pos = input.find_first_of("\\/", last); - if(last + pos == 0) { + std::string part; + + if(pos == std::string::npos) + part = input.substr(last); + else if(last + pos == 0) { #ifndef _WIN32 *attributes |= Path::Absolute; #endif @@ -65,11 +69,6 @@ static std::vector<std::string> Split(const std::string &input, int *attributes) last++; continue; } - - std::string part; - - if(pos == std::string::npos) - part = input.substr(last); else part = input.substr(last, pos - last); diff --git a/test/path.cpp b/test/path.cpp @@ -251,6 +251,11 @@ TEST_CASE("UNC path extended", M) { TEST_CASE("compare absolute to relative path (unix)", M) { REQUIRE(Path("/a/b") != Path("a/b")); } + +TEST_CASE("top-level unix absolute path (p=2359736)", M) { + Path p("/foo"); + REQUIRE(p[0] == "foo"); +} #endif TEST_CASE("remove last segment of path", M) {