From 93394902368a0fb2c25647f0d6205f5a43282933 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 26 Dec 2016 10:42:29 +0100 Subject: WINTERMUTE: only access -1th char of string if length > 0 in getFileName Fixes #6594 --- engines/wintermute/utils/path_util.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'engines/wintermute/utils/path_util.cpp') 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; } } -- cgit v1.2.3