[PATCH] lib: fwts_coreboot_cbmem: shift UL values rather than signed int values

Colin King colin.king at canonical.com
Tue Nov 13 12:43:54 UTC 2018


From: Colin Ian King <colin.king at canonical.com>

Shifting signed int values can result in undefined behaviour if the shift
is 31 places.  Make all shifted values of 1 unsigned long to ensure there
is no undefined behaviour. Cleans up clang error messages such as:

error: Shifting signed 32-bit value by 31 bits is undefined behaviour

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_coreboot_cbmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
index e02c523c..3802a0af 100644
--- a/src/lib/src/fwts_coreboot_cbmem.c
+++ b/src/lib/src/fwts_coreboot_cbmem.c
@@ -32,8 +32,8 @@
 #include <fcntl.h>
 
 
-#define CURSOR_MASK ((1 << 28) - 1)
-#define OVERFLOW (1 << 31)
+#define CURSOR_MASK ((1UL << 28) - 1)
+#define OVERFLOW (1UL << 31)
 
 #define LB_TAG_CBMEM_CONSOLE	0x0017
 #define LB_TAG_FORWARD		0x0011
-- 
2.19.1




More information about the fwts-devel mailing list