Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit 240f513

Browse files
committed
Fix signed shift warning for nlmacros BITMASK
Clang gives a warning for the BITMASK macro: Shifting a negative signed value is undefined [-Wshift-negative-value] The value in question is the literal "~0", which defaults to being a signed integer. It is clearly intended to be used as an unsigned integer, though, but happens to have the correct behavior because the compilers/hardware don't do anything too crazy with an overflowing left-shift in the signed case, despite it being undefined behavior.
1 parent 541a4f7 commit 240f513

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/nlmacros.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164

165165
// Each parameter evaluated once
166166
#ifndef BITMASK
167-
#define BITMASK(b, s) ((~(~0 << (b))) << (s))
167+
#define BITMASK(b, s) ((~(~0U << (b))) << (s))
168168
#endif
169169
#ifndef NL_BIT
170170
#define NL_BIT(s) BITMASK(1, s)

0 commit comments

Comments
 (0)