From: Rusty Russell Date: Mon, 9 Jan 2023 02:10:22 +0000 (+1030) Subject: bitops: fix -fsanitize=undefined warning: X-Git-Url: http://git.ozlabs.org/?a=commitdiff_plain;h=e46957c87a57ff2efd0b23e230599cce529f1f92;p=ccan bitops: fix -fsanitize=undefined warning: ``` /home/rusty/devel/cvs/ccan/ccan/bitops/test/run.c:28:3: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' bitops: Module's run and api tests pass (tests_pass): FAIL (+1/2) /home/rusty/devel/cvs/ccan/ccan/bitops/test/run.c:1..632 ``` Signed-off-by: Rusty Russell --- diff --git a/ccan/bitops/test/run.c b/ccan/bitops/test/run.c index 5dba932d..6bb3acf5 100644 --- a/ccan/bitops/test/run.c +++ b/ccan/bitops/test/run.c @@ -10,7 +10,7 @@ int main(void) plan_tests(68 + 6 * (31 + 63)); for (i = 0; i < 32; i++) - ok1(bitops_ffs32(1 << i) == i+1); + ok1(bitops_ffs32(1U << i) == i+1); ok1(bitops_ffs32(0) == 0); for (i = 0; i < 64; i++) ok1(bitops_ffs64((uint64_t)1 << i) == i+1); @@ -25,19 +25,19 @@ int main(void) ok1(bitops_ffs64(0) == 0); for (i = 0; i < 32; i++) - ok1(bitops_clz32(1 << i) == 31 - i); + ok1(bitops_clz32(1U << i) == 31 - i); for (i = 0; i < 64; i++) ok1(bitops_clz64((uint64_t)1 << i) == 63 - i); /* Lower bits don't effect results */ for (i = 0; i < 32; i++) - ok1(bitops_clz32((1 << i) + (1 << i)-1) == 31 - i); + ok1(bitops_clz32((1U << i) + (1U << i)-1) == 31 - i); for (i = 0; i < 64; i++) ok1(bitops_clz64(((uint64_t)1 << i) + ((uint64_t)1 << i)-1) == 63 - i); for (i = 0; i < 32; i++) - ok1(bitops_ctz32(1 << i) == i); + ok1(bitops_ctz32(1U << i) == i); for (i = 0; i < 64; i++) ok1(bitops_ctz64((uint64_t)1 << i) == i);