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<<N) is equivalent
to (1<<N)-1.

Signed-off-by: Iustin Pop <iustin@k1024.org>
This commit is contained in:
Iustin Pop
2019-02-23 23:16:33 +01:00
parent a15c02e572
commit 1345189baf

5
mt.c
View File

@@ -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" };