[Bf-blender-cvs] [9f283bee7ec] master: BLI_string_ref: avoid passing null to strncmp (quiet ASAN warning)
Campbell Barton
noreply at git.blender.org
Wed Jan 11 03:06:45 CET 2023
Commit: 9f283bee7ecfedabc7a6b46fb9f2cece6b3e31ec
Author: Campbell Barton
Date: Wed Jan 11 13:03:48 2023 +1100
Branches: master
https://developer.blender.org/rB9f283bee7ecfedabc7a6b46fb9f2cece6b3e31ec
BLI_string_ref: avoid passing null to strncmp (quiet ASAN warning)
The existing logic to avoid passing null only worked when both
strings were null.
===================================================================
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 14dee54d730..6ad4d6fd3af 100644
--- a/source/blender/blenlib/BLI_string_ref.hh
+++ b/source/blender/blenlib/BLI_string_ref.hh
@@ -608,9 +608,14 @@ constexpr bool operator==(StringRef a, StringRef b)
return false;
}
if (a.data() == b.data()) {
- /* This also avoids passing null to the call below, which would results in an ASAN warning. */
+ /* This also avoids passing null to the call below when both are null,
+ * 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;
+ }
return STREQLEN(a.data(), b.data(), size_t(a.size()));
}
More information about the Bf-blender-cvs
mailing list