Skip to content

Commit 582cb06

Browse files
committed
Fix UB on some bit array operations
C promotes arithmetic to int regardless of what type the values are eventually going to fit into. So if int is 32 bits, and leftover is 32 or more, UB. This was causing operations to read from the undefined (actually zero) part of the word.
1 parent 5d91796 commit 582cb06

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/core/array_bit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ CL_DEFUN SimpleBitVector_sp core__sbv_bit_not(SimpleBitVector_sp vec, SimpleBitV
134134
} \
135135
i = nwords; \
136136
if (leftover != 0) { \
137-
bit_array_word mask = ((1 << leftover) - 1) << (BIT_ARRAY_WORD_BITS - leftover); \
137+
bit_array_word mask = (((bit_array_word)1 << leftover) - 1) << (BIT_ARRAY_WORD_BITS - leftover); \
138138
word = bytes[i] & mask; \
139139
statement \
140140
} \

0 commit comments

Comments
 (0)