From 766ed3827547d5930c95b80c38a056fea358ef6b Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 22 Apr 2025 14:35:39 -0300 Subject: [PATCH] string: Fix UB on gneric strncmp Building with ubsan it triggers: UBSAN: Undefined behaviour in ../string/strncmp.c:103: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/strncmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/string/strncmp.c b/string/strncmp.c index 79a21c12a3..746d5acc25 100644 --- a/string/strncmp.c +++ b/string/strncmp.c @@ -100,7 +100,7 @@ strncmp_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, n); -- 2.47.2