[llvm] 3fbef5b - Fixed a signed integer overflow in BitstreamWriter.h which is found by UBSAN.

Ying Yi via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 05:29:36 PST 2024


Author: Ying Yi
Date: 2024-01-03T13:28:13Z
New Revision: 3fbef5b8e98f7365e9424339f53950eb6c1b3c3c

URL: https://github.com/llvm/llvm-project/commit/3fbef5b8e98f7365e9424339f53950eb6c1b3c3c
DIFF: https://github.com/llvm/llvm-project/commit/3fbef5b8e98f7365e9424339f53950eb6c1b3c3c.diff

LOG: Fixed a signed integer overflow in BitstreamWriter.h which is found by UBSAN.

https://github.com/llvm/llvm-project/pull/75213

Added: 
    

Modified: 
    llvm/include/llvm/Bitstream/BitstreamWriter.h

Removed: 
    


################################################################################
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