[llvm] [Bitcode] Fix a signed integer overflow in BitstreamWriter.h (PR #75213)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 03:22:52 PST 2024
https://github.com/MaggieYingYi updated https://github.com/llvm/llvm-project/pull/75213
>From 45a019e15e1b7661dbbc94e1578fededf46493ba Mon Sep 17 00:00:00 2001
From: Ying Yi <ying.yi at sony.com>
Date: Tue, 12 Dec 2023 12:13:47 +0000
Subject: [PATCH] Fixed a signed integer overflow in BitstreamWriter.h which is
found by UBSAN.
---
llvm/include/llvm/Bitstream/BitstreamWriter.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h
index f7d362b5d70ceb..c726508cd52851 100644
--- a/llvm/include/llvm/Bitstream/BitstreamWriter.h
+++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h
@@ -239,7 +239,8 @@ class BitstreamWriter {
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
while (Val >= Threshold) {
- Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
+ Emit((Val & ((1U << (NumBits - 1)) - 1)) | (1U << (NumBits - 1)),
+ NumBits);
Val >>= NumBits-1;
}
@@ -255,7 +256,8 @@ class BitstreamWriter {
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
while (Val >= Threshold) {
- Emit(((uint32_t)Val & ((1 << (NumBits - 1)) - 1)) | (1 << (NumBits - 1)),
+ Emit(((uint32_t)Val & ((1U << (NumBits - 1)) - 1)) |
+ (1U << (NumBits - 1)),
NumBits);
Val >>= NumBits-1;
}
More information about the llvm-commits
mailing list