Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/include/sys Avoid undefined behavior in an ATF test: t...



details:   https://anonhg.NetBSD.org/src/rev/e545f761e886
branches:  trunk
changeset: 363403:e545f761e886
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Jul 25 22:00:32 2018 +0000

description:
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.

diffstat:

 tests/include/sys/t_bitops.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 783d23f98442 -r e545f761e886 tests/include/sys/t_bitops.c
--- a/tests/include/sys/t_bitops.c      Wed Jul 25 21:51:32 2018 +0000
+++ b/tests/include/sys/t_bitops.c      Wed Jul 25 22:00:32 2018 +0000
@@ -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 @@
        uint32_t x;
 
        for (i = 0; i < 32; i++) {
-               x = 1 << i;
+               x = 1U << i;
                ATF_REQUIRE(ilog2(x) == i);
        }
 }



Home | Main Index | Thread Index | Old Index