Skip to content

Commit 3fbef5b

Browse files
committed
Fixed a signed integer overflow in BitstreamWriter.h which is found by UBSAN.
#75213
1 parent 9862491 commit 3fbef5b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/include/llvm/Bitstream/BitstreamWriter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ class BitstreamWriter {
239239

240240
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
241241
while (Val >= Threshold) {
242-
Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
242+
Emit((Val & ((1U << (NumBits - 1)) - 1)) | (1U << (NumBits - 1)),
243+
NumBits);
243244
Val >>= NumBits-1;
244245
}
245246

@@ -255,7 +256,8 @@ class BitstreamWriter {
255256

256257
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
257258
while (Val >= Threshold) {
258-
Emit(((uint32_t)Val & ((1 << (NumBits - 1)) - 1)) | (1 << (NumBits - 1)),
259+
Emit(((uint32_t)Val & ((1U << (NumBits - 1)) - 1)) |
260+
(1U << (NumBits - 1)),
259261
NumBits);
260262
Val >>= NumBits-1;
261263
}

0 commit comments

Comments
 (0)