[PATCH] D119307: [Bitstream] Fix UB in left-shift in ReadVBR

Jan Korous via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 11 17:22:52 PST 2022


jkorous marked an inline comment as done.
jkorous added inline comments.


================
Comment at: llvm/include/llvm/Bitstream/BitstreamReader.h:250-255
+      if (Mask > 1) {
+        if (MaskBitOrder - 1 + NextBit >= 32) {
+          return make_error<StringError>("Invalid NumBits or NextBit value",
+                                         llvm::inconvertibleErrorCode());
+        }
+      }
----------------
browneee wrote:
> Why not simpler condition?
> 
> ```
> if (NextBit >= 32) { ... }
> ```
> 
> And move later in the loop for a little less overhead (the first iteration will always be NextBit==0).
You're absolutely right.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119307/new/

https://reviews.llvm.org/D119307



More information about the llvm-commits mailing list