[PATCH v2 04/14] use bits_mask() for predefined_max()

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

 



Creating a bit mask using '(1 << n) - 1' is undefined if
n is as big as the width of an int.

Use the safe helper bits_mask() to create the mask/value
for predefined_max().

Note: predefined_max() is currently correct only for signed types.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib.c b/lib.c
index db33e58b2..ad583da93 100644
--- a/lib.c
+++ b/lib.c
@@ -45,6 +45,7 @@
 #include "linearize.h"
 #include "target.h"
 #include "version.h"
+#include "bits.h"
 
 int verbose, optimize_level, optimize_size, preprocessing;
 int die_if_error = 0;
@@ -1162,7 +1163,7 @@ static void predefined_width(const char *name, unsigned bits)
 
 static void predefined_max(const char *name, const char *suffix, unsigned bits)
 {
-	unsigned long long max = (1ULL << (bits - 1 )) - 1;
+	unsigned long long max = bits_mask(bits - 1);
 	char buf[32];
 
 	snprintf(buf, sizeof(buf), "__%s_MAX__", name);
-- 
2.19.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux