diff --git a/runtime/ecma_string.cpp b/runtime/ecma_string.cpp index 8b6d085c3b5d36c84a27ff253cd544ca3146a78c..d62248bc55a5bdd39cc187d8d3029c241a3fefc9 100644 --- a/runtime/ecma_string.cpp +++ b/runtime/ecma_string.cpp @@ -375,13 +375,13 @@ bool EcmaString::StringCopy(Span &dst, size_t dstMax, Span &src, siz return true; } -static int32_t ComputeHashForUtf8(const uint8_t *utf8Data) +static int32_t ComputeHashForUtf8(const uint8_t *utf8Data, size_t utf8Len) { if (utf8Data == nullptr) { return 0; } uint32_t hash = 0; - while (*utf8Data != '\0') { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + while (utf8Len-- > 0) { constexpr size_t SHIFT = 5; hash = (hash << SHIFT) - hash + *utf8Data++; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } @@ -409,7 +409,7 @@ uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len { uint32_t hash; if (canBeCompress) { - hash = ComputeHashForUtf8(utf8Data); + hash = ComputeHashForUtf8(utf8Data, utf8Len); } else { auto utf16Len = base::utf_helper::Utf8ToUtf16Size(utf8Data, utf8Len); PandaVector tmpBuffer(utf16Len);