[runtime] Fixed UB with signed overflow

This commit is contained in:
Igor Chevdar
2021-01-29 18:18:56 +05:00
committed by Vasily Levchenko
parent c8633d8bda
commit c12d79176a
3 changed files with 3 additions and 3 deletions
@@ -99,7 +99,7 @@ int polyHash_arm(int length, uint16_t const* str) {
// Vectorization is not supported. // Vectorization is not supported.
return polyHash_naive(length, str); return polyHash_naive(length, str);
} }
int res; uint32_t res;
if (length < 488) if (length < 488)
res = NeonTraits::polyHashUnalignedUnrollUpTo16(length / 4, str); res = NeonTraits::polyHashUnalignedUnrollUpTo16(length / 4, str);
else else
@@ -9,7 +9,7 @@
#include <cstdint> #include <cstdint>
inline int polyHash_naive(int length, uint16_t const* str) { inline int polyHash_naive(int length, uint16_t const* str) {
int res = 0; uint32_t res = 0;
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
res = res * 31 + str[i]; res = res * 31 + str[i];
return res; return res;
@@ -143,7 +143,7 @@ int polyHash_x86(int length, uint16_t const* str) {
// Either vectorization is not supported or the string is too short to gain from it. // Either vectorization is not supported or the string is too short to gain from it.
return polyHash_naive(length, str); return polyHash_naive(length, str);
} }
int res; uint32_t res;
if (length < 32) if (length < 32)
res = SSETraits::polyHashUnalignedUnrollUpTo8(length / 4, str); res = SSETraits::polyHashUnalignedUnrollUpTo8(length / 4, str);
else if (!avx2Supported) else if (!avx2Supported)