diff options
Diffstat (limited to 'source/core/slang-string.h')
| -rw-r--r-- | source/core/slang-string.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 4975e9ec6..8a9e83cd1 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -119,8 +119,25 @@ namespace Slang bool operator==(UnownedStringSlice const& other) const { - return size() == other.size() - && memcmp(begin(), other.begin(), size()) == 0; + // Note that memcmp is undefined when passed in null ptrs, so if we want to handle + // we need to cover that case. + // Can only be nullptr if size is 0. + auto thisSize = size(); + auto otherSize = other.size(); + + if (thisSize != otherSize) + { + return false; + } + + const char*const thisChars = begin(); + const char*const otherChars = other.begin(); + if (thisChars == otherChars || thisSize == 0) + { + return true; + } + SLANG_ASSERT(thisChars && otherChars); + return memcmp(thisChars, otherChars, thisSize) == 0; } bool operator==(char const* str) const |
