Module Name:    src
Committed By:   kamil
Date:           Wed Jul 25 22:00:32 UTC 2018

Modified Files:
        src/tests/include/sys: t_bitops.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/include/sys/t_bitops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/include/sys/t_bitops.c
diff -u src/tests/include/sys/t_bitops.c:1.19 src/tests/include/sys/t_bitops.c:1.20
--- src/tests/include/sys/t_bitops.c:1.19	Sat Mar 21 05:50:19 2015
+++ src/tests/include/sys/t_bitops.c	Wed Jul 25 22:00:32 2018
@@ -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.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #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>
 
@@ -186,7 +186,7 @@ ATF_TC_BODY(ilog2_32bit, tc)
 	uint32_t x;
 
 	for (i = 0; i < 32; i++) {
-		x = 1 << i;
+		x = 1U << i;
 		ATF_REQUIRE(ilog2(x) == i);
 	}
 }

Reply via email to