From d3e8d63a8c455d09ff3660cc158a28439d5eb06d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Jan 2023 20:00:59 +1100 Subject: [PATCH] Fix error in StringRef equality Regression in [0] wasn't correct as it's important for empty strings to be equal to nullptr. [0]: 9f283bee7ecfedabc7a6b46fb9f2cece6b3e31ec --- source/blender/blenlib/BLI_string_ref.hh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/blender/blenlib/BLI_string_ref.hh b/source/blender/blenlib/BLI_string_ref.hh index 6ad4d6fd3af..4f6f2cbfa41 100644 --- a/source/blender/blenlib/BLI_string_ref.hh +++ b/source/blender/blenlib/BLI_string_ref.hh @@ -612,9 +612,13 @@ constexpr bool operator==(StringRef a, StringRef b) * which would results in an ASAN warning. */ return true; } - if (!a.data() || !b.data()) { - /* Account for a single value being null, resulting in an ASAN warning. */ - return false; + /* Account for a single value being null, resulting in an ASAN warning. + * Ensure an empty string is equal to a string with a null pointer. */ + if (!a.data()) { + return *b.data() == '\0'; + } + if (!b.data()) { + return *a.data() == '\0'; } return STREQLEN(a.data(), b.data(), size_t(a.size())); }