[Scummvm-git-logs] scummvm master -> 5b4e26322e190e2594ce12adfcddf187e3740341

lephilousophe noreply at scummvm.org
Sun Jan 14 13:07:17 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:
5b4e26322e COMMON: Don't fail when comparing empty strings


Commit: 5b4e26322e190e2594ce12adfcddf187e3740341
    https://github.com/scummvm/scummvm/commit/5b4e26322e190e2594ce12adfcddf187e3740341
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-01-14T14:06:41+01:00

Commit Message:
COMMON: Don't fail when comparing empty strings

Add tests for this.

Changed paths:
    common/str-base.cpp
    test/common/str.h


diff --git a/common/str-base.cpp b/common/str-base.cpp
index b3c2c3a50ec..7d233b0180b 100644
--- a/common/str-base.cpp
+++ b/common/str-base.cpp
@@ -324,6 +324,11 @@ TEMPLATE bool BASESTRING::operator!=(const value_type *x) const {
 }
 
 TEMPLATE int BASESTRING::compareTo(const BaseString &x) const {
+	if (_size == 0 &&
+	    x.size() == 0) {
+		return 0;
+	}
+
 	int n = cMemCmp(_str, x._str, MIN<uint32>(_size, x.size()));
 	if (n != 0)
 		return n;
@@ -1106,7 +1111,6 @@ TEMPLATE T *BASESTRING::cMemChr(value_type *str, value_type c, size_t count) {
 TEMPLATE int BASESTRING::cMemCmp(const value_type* ptr1, const value_type* ptr2, size_t count) {
 	assert(ptr1);
 	assert(ptr2);
-	assert(count);
 
 	for (size_t i = 0; i < count; ++i) {
 		value_type sc = ptr1[i];
diff --git a/test/common/str.h b/test/common/str.h
index 9ebe42be189..3ba30de8032 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -722,7 +722,7 @@ class StringTestSuite : public CxxTest::TestSuite
 	}
 
 	void test_ustr_comparison() {
-		Common::U32String a("abc"), b("abd");
+		Common::U32String a("abc"), b("abd"), c, d("");
 
 		TS_ASSERT_EQUALS(a, a);
 		TS_ASSERT_EQUALS(b, b);
@@ -740,5 +740,9 @@ class StringTestSuite : public CxxTest::TestSuite
 		TS_ASSERT(b > a);
 		TS_ASSERT(b >= b);
 		TS_ASSERT(b >= a);
+
+		TS_ASSERT(c == d);
+		TS_ASSERT(a > c);
+		TS_ASSERT(c < a);
 	}
 };




More information about the Scummvm-git-logs mailing list