diff --git a/lib/std/core/string.c3 b/lib/std/core/string.c3 index 190cea02c..6aeaf49cf 100644 --- a/lib/std/core/string.c3 +++ b/lib/std/core/string.c3 @@ -582,6 +582,7 @@ fn bool ZString.eq(self, ZString other) @operator(==) char* a = self; char* b = other; if (a == b) return true; + if (!a || !b) return false; for (;; a++, b++) { char c = *a; diff --git a/releasenotes.md b/releasenotes.md index da040f434..1c645502a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -13,6 +13,7 @@ - mkdir/rmdir would not work properly with substring paths on non-windows platforms. - Hex string formatter check incorrectly rejected slices. - Correctly reject interface methods `type` and `ptr`. +- Comparing a null ZString with a non-null ZString would crash. ### Stdlib changes diff --git a/test/unit/stdlib/core/string.c3 b/test/unit/stdlib/core/string.c3 index 2235ad2d8..3e37225ec 100644 --- a/test/unit/stdlib/core/string.c3 +++ b/test/unit/stdlib/core/string.c3 @@ -197,7 +197,12 @@ fn void test_zstring() ZString test3 = "bye"; assert(test.zstr_tcopy() == test2); assert(test.zstr_tcopy() != test3); + ZString null_string; + assert(test != null_string); + assert(null_string == null_string); + assert(null_string != test); } + fn void test_replace() { String test = "Befriend some dragons?";