diff options
| author | Duncan Sands <baldrick@free.fr> | 2012-08-21 13:47:25 +0000 |
|---|---|---|
| committer | Duncan Sands <baldrick@free.fr> | 2012-08-21 13:47:25 +0000 |
| commit | 68256859ff14d122870de9dbe67a99c6b8fb795e (patch) | |
| tree | bdb0bc1196bd2e66147bdec6faece9e48904e8c2 | |
| parent | f39c1a3f72ee156321c0a26be287c4e8ce717a3f (diff) | |
| download | bcm5719-llvm-68256859ff14d122870de9dbe67a99c6b8fb795e.tar.gz bcm5719-llvm-68256859ff14d122870de9dbe67a99c6b8fb795e.zip | |
PVS-Studio noticed that EmitVBR64 would perform undefined behaviour if the
number of bits was bigger than 32. I checked every use of this function
that I could find and it looks like the maximum number of bits is 32, so I've
added an assertion checking this property, and a type cast to (hopefully) stop
PVS-Studio from warning about this in the future.
llvm-svn: 162277
| -rw-r--r-- | llvm/include/llvm/Bitcode/BitstreamWriter.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/include/llvm/Bitcode/BitstreamWriter.h b/llvm/include/llvm/Bitcode/BitstreamWriter.h index 475da133f8a..65933a28e43 100644 --- a/llvm/include/llvm/Bitcode/BitstreamWriter.h +++ b/llvm/include/llvm/Bitcode/BitstreamWriter.h @@ -155,6 +155,7 @@ public: } void EmitVBR(uint32_t Val, unsigned NumBits) { + assert(NumBits <= 32 && "Too many bits to emit!"); uint32_t Threshold = 1U << (NumBits-1); // Emit the bits with VBR encoding, NumBits-1 bits at a time. @@ -167,10 +168,11 @@ public: } void EmitVBR64(uint64_t Val, unsigned NumBits) { + assert(NumBits <= 32 && "Too many bits to emit!"); if ((uint32_t)Val == Val) return EmitVBR((uint32_t)Val, NumBits); - uint64_t Threshold = 1U << (NumBits-1); + uint64_t Threshold = uint64_t(1U << (NumBits-1)); // Emit the bits with VBR encoding, NumBits-1 bits at a time. while (Val >= Threshold) { |

