summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix/Path.inc
diff options
context:
space:
mode:
authorJeff Cohen <jeffc@jolt-lang.org>2005-07-09 18:42:02 +0000
committerJeff Cohen <jeffc@jolt-lang.org>2005-07-09 18:42:02 +0000
commit5b106d0fed4d8eb234c01bb84869cf265180c761 (patch)
treeac8cdcf16d0080f60dd3262dca726ca6b24dfe26 /llvm/lib/System/Unix/Path.inc
parent2d85f5697d8c5f9a028848ecf02faf9852951f80 (diff)
downloadbcm5719-llvm-5b106d0fed4d8eb234c01bb84869cf265180c761.tar.gz
bcm5719-llvm-5b106d0fed4d8eb234c01bb84869cf265180c761.zip
1. Fix bug in getBaseName where it mishandles suffixes
2. Fix bug in eraseSuffix where it allows /path/.suffix to become /path/ llvm-svn: 22362
Diffstat (limited to 'llvm/lib/System/Unix/Path.inc')
-rw-r--r--llvm/lib/System/Unix/Path.inc8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc
index 3f2e90e9d36..9d5e7fa9100 100644
--- a/llvm/lib/System/Unix/Path.inc
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud