diff options
author | Jeff Cohen <jeffc@jolt-lang.org> | 2005-07-09 18:42:02 +0000 |
---|---|---|
committer | Jeff Cohen <jeffc@jolt-lang.org> | 2005-07-09 18:42:02 +0000 |
commit | 73f36671b23cd299550060e4167b52d1e22fd314 (patch) | |
tree | 06a7ab05b783a4f3a3138c83015146e30457ab7b /lib/System/Unix | |
parent | 8b2d1aa37b8a1d8993c184a0255fefb47c6b9b7c (diff) |
1. Fix bug in getBaseName where it mishandles suffixes
2. Fix bug in eraseSuffix where it allows /path/.suffix to become /path/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22362 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 3f2e90e9d3..9d5e7fa910 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -271,7 +271,11 @@ Path::getBasename() const { else slash++; - return path.substr(slash, path.rfind('.')); + size_t dot = path.rfind('.'); + if (dot == std::string::npos || dot < slash) + return path.substr(slash); + else + return path.substr(slash, dot - slash); } bool Path::hasMagicNumber(const std::string &Magic) const { @@ -521,7 +525,7 @@ Path::eraseSuffix() { size_t dotpos = path.rfind('.',path.size()); size_t slashpos = path.rfind('/',path.size()); if (dotpos != std::string::npos) { - if (slashpos == std::string::npos || dotpos > slashpos) { + if (slashpos == std::string::npos || dotpos > slashpos+1) { path.erase(dotpos, path.size()-dotpos); return true; } |