From 1345189baf2c4fef532cead4939e0579cad1986f Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sat, 23 Feb 2019 23:16:33 +0100 Subject: [PATCH] Remove left-shifting of negative values Left-shifting of negative values is undefined behaviour according to the C standard, because it depends on the exact representation. This code, copied from the Linux kernel, is intended for 2's complement and can be replaced by well-defined behaviour: ~(-1< --- mt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mt.c b/mt.c index 7564f9c..8f795e6 100644 --- a/mt.c +++ b/mt.c @@ -682,8 +682,9 @@ static int do_status(int mtfd, #define ST_NBR_MODES (1 << ST_NBR_MODE_BITS) #define ST_MODE_SHIFT (7 - ST_NBR_MODE_BITS) #define ST_MODE_MASK ((ST_NBR_MODES - 1) << ST_MODE_SHIFT) -#define TAPE_NR(minor) \ - ((((minor) & ~255) >> (ST_NBR_MODE_BITS + 1)) | ((minor) & ~(-1 << ST_MODE_SHIFT))) +#define TAPE_NR(minor) \ + ((((minor) & ~255) >> (ST_NBR_MODE_BITS + 1)) | \ + ((minor) & ((1 << ST_MODE_SHIFT) - 1))) #define TAPE_MODE(minor) (((minor)&ST_MODE_MASK) >> ST_MODE_SHIFT) static const char *st_formats[] = { "", "r", "k", "s", "l", "t", "o", "u", "m", "v", "p", "x", "a", "y", "q", "z" };