[Scummvm-git-logs] scummvm master -> aceaf9981617120ea9e6ba138bc521b6a2f56742
lephilousophe
noreply at scummvm.org
Fri Feb 2 07:09:46 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
aceaf99816 COMMON: Fix bug #14892
Commit: aceaf9981617120ea9e6ba138bc521b6a2f56742
https://github.com/scummvm/scummvm/commit/aceaf9981617120ea9e6ba138bc521b6a2f56742
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-02-02T08:06:59+01:00
Commit Message:
COMMON: Fix bug #14892
When both paths were equal, suffix was incremented one char too much and
went off the string.
Add test cases to check for this.
Changed paths:
common/path.cpp
test/common/path.h
diff --git a/common/path.cpp b/common/path.cpp
index 6346930c6e0..7adad9b59b1 100644
--- a/common/path.cpp
+++ b/common/path.cpp
@@ -601,13 +601,20 @@ const char *Path::getSuffix(const Common::Path &other) const {
if (_str.hasPrefix(other._str)) {
const char *suffix = _str.c_str() + other._str.size();
if (!other.isSeparatorTerminated()) {
- // Make sure we didn't end up in the middle of some path component
- if (*suffix != SEPARATOR && *suffix != '\x00') {
+ if (*suffix == SEPARATOR) {
+ // Skip the separator
+ return suffix + 1;
+ } else if (*suffix == '\x00') {
+ // Both paths are equal: return end of string
+ return suffix;
+ } else {
+ // We are in the middle of some path component: this is not relative
return nullptr;
}
- suffix++;
+ } else {
+ // Other already had a separator: this is relative and starts with next component
+ return suffix;
}
- return suffix;
} else {
return nullptr;
}
diff --git a/test/common/path.h b/test/common/path.h
index 950d2300a7f..cfddeced759 100644
--- a/test/common/path.h
+++ b/test/common/path.h
@@ -301,6 +301,10 @@ class PathTestSuite : public CxxTest::TestSuite
// Everything is relative to empty
TS_ASSERT_EQUALS(p1.isRelativeTo(p), true);
TS_ASSERT_EQUALS(p2.isRelativeTo(p), true);
+ // Everything is relative to itself
+ TS_ASSERT_EQUALS(p1.isRelativeTo(p1), true);
+ TS_ASSERT_EQUALS(p2.isRelativeTo(p2), true);
+
// A path is not relative to empty one
TS_ASSERT_EQUALS(p.isRelativeTo(p1), false);
@@ -326,6 +330,10 @@ class PathTestSuite : public CxxTest::TestSuite
// Everything is relative to empty
TS_ASSERT_EQUALS(p1.relativeTo(p).toString(), TEST_PATH);
TS_ASSERT_EQUALS(p2.relativeTo(p).toString(), TEST_ESCAPED1_PATH);
+ // Everything is relative to itself
+ TS_ASSERT_EQUALS(p1.relativeTo(p1), p);
+ TS_ASSERT_EQUALS(p2.relativeTo(p2), p);
+
// A path is not relative to empty one
TS_ASSERT_EQUALS(p.relativeTo(p1), p);
More information about the Scummvm-git-logs
mailing list