From c12d79176a5c29531f0b8f4fa11eeaac3130813d Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 29 Jan 2021 18:18:56 +0500 Subject: [PATCH] [runtime] Fixed UB with signed overflow --- kotlin-native/runtime/src/main/cpp/polyhash/arm.cpp | 2 +- kotlin-native/runtime/src/main/cpp/polyhash/naive.h | 2 +- kotlin-native/runtime/src/main/cpp/polyhash/x86.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kotlin-native/runtime/src/main/cpp/polyhash/arm.cpp b/kotlin-native/runtime/src/main/cpp/polyhash/arm.cpp index 1e194af701f..a31474a60a7 100644 --- a/kotlin-native/runtime/src/main/cpp/polyhash/arm.cpp +++ b/kotlin-native/runtime/src/main/cpp/polyhash/arm.cpp @@ -99,7 +99,7 @@ int polyHash_arm(int length, uint16_t const* str) { // Vectorization is not supported. return polyHash_naive(length, str); } - int res; + uint32_t res; if (length < 488) res = NeonTraits::polyHashUnalignedUnrollUpTo16(length / 4, str); else diff --git a/kotlin-native/runtime/src/main/cpp/polyhash/naive.h b/kotlin-native/runtime/src/main/cpp/polyhash/naive.h index 20ca0a85052..762763c0dbd 100644 --- a/kotlin-native/runtime/src/main/cpp/polyhash/naive.h +++ b/kotlin-native/runtime/src/main/cpp/polyhash/naive.h @@ -9,7 +9,7 @@ #include inline int polyHash_naive(int length, uint16_t const* str) { - int res = 0; + uint32_t res = 0; for (int i = 0; i < length; ++i) res = res * 31 + str[i]; return res; diff --git a/kotlin-native/runtime/src/main/cpp/polyhash/x86.cpp b/kotlin-native/runtime/src/main/cpp/polyhash/x86.cpp index a5b2b321637..406a33fccb9 100644 --- a/kotlin-native/runtime/src/main/cpp/polyhash/x86.cpp +++ b/kotlin-native/runtime/src/main/cpp/polyhash/x86.cpp @@ -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. return polyHash_naive(length, str); } - int res; + uint32_t res; if (length < 32) res = SSETraits::polyHashUnalignedUnrollUpTo8(length / 4, str); else if (!avx2Supported)