]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Fix UB on tesf-ffs
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 23 Apr 2025 19:20:28 +0000 (16:20 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:39 +0000 (09:25 -0300)
UBSAN: Undefined behaviour in test-ffs.c:48:3 left shift of 1 by 31 cannot be represented in type 'int'

string/test-ffs.c

index 3493cca421f9acf0ebaae6bfe0e606891897c9c5..db4f64f96ef56fb3bab0ca5242774fb2269c8b8a 100644 (file)
@@ -40,9 +40,10 @@ do_test (void)
 #define TEST(fct, type) \
   try (#fct, 0, fct ((type) 0), 0);                                          \
   for (i=0 ; i < 8 * sizeof (type); i++)                                     \
-    try (#fct, 1ll << i, fct (((type) 1) << i), i + 1);                              \
+    try (#fct, 1ull << i, fct (((unsigned type) 1) << i), i + 1);            \
   for (i=0 ; i < 8 * sizeof (type) ; i++)                                    \
-    try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
+    try (#fct, (~((unsigned type) 0) >> i) << i,                             \
+        fct ((~((unsigned type) 0) >> i) << i), i + 1);\
   try (#fct, 0x80008000, fct ((type) 0x80008000), 16)
 
   TEST (ffs, int);