summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2019-06-08 10:06:40 -0400
committerMark Wielaard <mark@klomp.org>2019-06-24 15:24:21 +0200
commit16f2c753f9959e8d7c7e1fa771b8ccc5821427aa (patch)
tree67ba6a528c0b57a51acaeac2e1ef5ae5d8229369
parentbzip2: Fix return value when combining --test,-t and -q. (diff)
downloadbzip2-16f2c753f9959e8d7c7e1fa771b8ccc5821427aa.tar.gz
bzip2-16f2c753f9959e8d7c7e1fa771b8ccc5821427aa.tar.bz2
bzip2-16f2c753f9959e8d7c7e1fa771b8ccc5821427aa.tar.xz
Fix undefined behavior in the macros SET_BH, CLEAR_BH, & ISSET_BH
These macros contain this pattern: 1 << ((Int32_value) & 31 This causes the undefined behavior sanitizers in clang and gcc to complain because the shift, while ultimately stored to an unsigned variable, is done as a signed value. Adding a cast to unsigned for the int32 value resolves this issue.
-rw-r--r--blocksort.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/blocksort.c b/blocksort.c
index 830d1b4..aa36766 100644
--- a/blocksort.c
+++ b/blocksort.c
@@ -202,9 +202,9 @@ void fallbackQSort3 ( UInt32* fmap,
202 bhtab [ 0 .. 2+(nblock/32) ] destroyed 202 bhtab [ 0 .. 2+(nblock/32) ] destroyed
203*/ 203*/
204 204
205#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31)) 205#define SET_BH(zz) bhtab[(zz) >> 5] |= ((UInt32)1 << ((zz) & 31))
206#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31)) 206#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~((UInt32)1 << ((zz) & 31))
207#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31))) 207#define ISSET_BH(zz) (bhtab[(zz) >> 5] & ((UInt32)1 << ((zz) & 31)))
208#define WORD_BH(zz) bhtab[(zz) >> 5] 208#define WORD_BH(zz) bhtab[(zz) >> 5]
209#define UNALIGNED_BH(zz) ((zz) & 0x01f) 209#define UNALIGNED_BH(zz) ((zz) & 0x01f)
210 210