aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/utils/path_util.cpp
diff options
context:
space:
mode:
authorTobia Tesan2016-12-26 10:42:29 +0100
committerTobia Tesan2016-12-26 12:02:56 +0100
commit93394902368a0fb2c25647f0d6205f5a43282933 (patch)
tree38e3a0cdcd27d234e8ba7084b122431007c6fb69 /engines/wintermute/utils/path_util.cpp
parente3fdd8d5fe5b739b28c67539bbdb0b596f9dacbe (diff)
downloadscummvm-rg350-93394902368a0fb2c25647f0d6205f5a43282933.tar.gz
scummvm-rg350-93394902368a0fb2c25647f0d6205f5a43282933.tar.bz2
scummvm-rg350-93394902368a0fb2c25647f0d6205f5a43282933.zip
WINTERMUTE: only access -1th char of string if length > 0 in getFileName
Fixes #6594
Diffstat (limited to 'engines/wintermute/utils/path_util.cpp')
-rw-r--r--engines/wintermute/utils/path_util.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp
index db986061f8..60a07f0bf0 100644
--- a/engines/wintermute/utils/path_util.cpp
+++ b/engines/wintermute/utils/path_util.cpp
@@ -63,6 +63,10 @@ Common::String PathUtil::combine(const Common::String &path1, const Common::Stri
return newPath1 + newPath2;
}
+bool PathUtil::hasTrailingSlash(const Common::String &path) {
+ return (path.size() > 0 && path[path.size() - 1 ] == '/');
+}
+
//////////////////////////////////////////////////////////////////////////
Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
@@ -74,10 +78,10 @@ Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String PathUtil::getFileName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
Common::String lastPart = Common::lastPathComponent(newPath, '/');
- if (lastPart[lastPart.size() - 1 ] != '/') {
- return lastPart;
+ if (hasTrailingSlash(newPath)) {
+ return Common::String("");
} else {
- return path;
+ return lastPart;
}
}