Avoid undefined behavior in an ATF test: t_bitops

Do not change the signedness bit with a left shift operation.
Switch to unsigned integer to prevent this.

t_bitops.c:189:9, left shift of 1 by 31 places cannot be represented in type 'int'

Detected with micro-UBSan in the user mode.
This commit is contained in:
kamil 2018-07-25 22:00:32 +00:00
parent d61d73f803
commit 95a05eda65
1 changed files with 3 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $ */ /* $NetBSD: t_bitops.c,v 1.20 2018/07/25 22:00:32 kamil Exp $ */
/*- /*-
* Copyright (c) 2011, 2012 The NetBSD Foundation, Inc. * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__RCSID("$NetBSD: t_bitops.c,v 1.19 2015/03/21 05:50:19 isaki Exp $"); __RCSID("$NetBSD: t_bitops.c,v 1.20 2018/07/25 22:00:32 kamil Exp $");
#include <atf-c.h> #include <atf-c.h>
@ -186,7 +186,7 @@ ATF_TC_BODY(ilog2_32bit, tc)
uint32_t x; uint32_t x;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
x = 1 << i; x = 1U << i;
ATF_REQUIRE(ilog2(x) == i); ATF_REQUIRE(ilog2(x) == i);
} }
} }