]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Fix UB on generic strcmp
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 22 Apr 2025 17:30:06 +0000 (14:30 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:21 +0000 (14:21 -0300)
Building with ubsan it trigger:

UBSAN: Undefined behaviour in ../string/strcmp.c:92:12 shift exponent 32 is too large for 32-bit type 'int'

Use an unsigned constant literal for MERGE, since op_t is defined
as unsigned.

string/strcmp.c

index f79dd926d384478608bd84bc5c461a245723b7d7..3a325115b2393c405b12a4f9de9b0fccde5b8a38 100644 (file)
@@ -89,7 +89,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs)
 
       /* Load the final word of P1 and align the final partial of P2.  */
       w1 = *x1++;
-      w2 = MERGE (w2b, sh_1, 0, sh_2);
+      w2 = MERGE (w2b, sh_1, 0UL, sh_2);
     }
 
   return final_cmp (w1, w2);