]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
locale: Fix UB in elem_hash
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 18 Apr 2025 12:40:51 +0000 (09:40 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:20:40 +0000 (14:20 -0300)
The ubsan triggers:

UBSAN: Undefined behaviour in ./elem-hash.h:27:14 left shift of 360447856 by 3 cannot be represented in type 'int'

Using unsigned shift here zero fill like signed.

locale/elem-hash.h

index 5d34ec43f32ac091e80baec6a347a327565aac05..8052b0fe6d67f0995d7d35591b81d940da2c8125 100644 (file)
@@ -24,7 +24,7 @@ elem_hash (const char *str, int32_t n)
 
   while (n-- > 0)
     {
-      result <<= 3;
+      result = (uint32_t)result << 3;
       result += *str++;
     }