[Bf-blender-cvs] [d3e8d63a8c4] master: Fix error in StringRef equality
Campbell Barton
noreply at git.blender.org
Wed Jan 11 10:08:42 CET 2023
Commit: d3e8d63a8c455d09ff3660cc158a28439d5eb06d
Author: Campbell Barton
Date: Wed Jan 11 20:00:59 2023 +1100
Branches: master
https://developer.blender.org/rBd3e8d63a8c455d09ff3660cc158a28439d5eb06d
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
===================================================================
M source/blender/blenlib/BLI_string_ref.hh
===================================================================
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()));
}
More information about the Bf-blender-cvs
mailing list