diff mbox series

[08/11] locale: Fix UB in elem_hash

Message ID 20250507142110.3452012-9-adhemerval.zanella@linaro.org
State New
Headers show
Series Add initial support for --enable-ubsan | expand

Commit Message

Adhemerval Zanella May 7, 2025, 2:17 p.m. UTC
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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/locale/elem-hash.h b/locale/elem-hash.h
index 5d34ec43f3..8052b0fe6d 100644
--- a/locale/elem-hash.h
+++ b/locale/elem-hash.h
@@ -24,7 +24,7 @@  elem_hash (const char *str, int32_t n)
 
   while (n-- > 0)
     {
-      result <<= 3;
+      result = (uint32_t)result << 3;
       result += *str++;
     }