Skip to content

Commit 7a2dfe2

Browse files
author
Andy Kaylor
committed
Avoid unintended integer overflow in bitstream handling
This change fixes two cases detected by static analysis where an operation is being performed on a 32-bit integer which may overflow and the result is assigned to a 64-bit integer. Differential Revision: https://reviews.llvm.org/D144661
1 parent ca2eabd commit 7a2dfe2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

llvm/include/llvm/Bitstream/BitstreamReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class SimpleBitstreamCursor {
115115

116116
/// Return the bit # of the bit we are reading.
117117
uint64_t GetCurrentBitNo() const {
118-
return NextChar*CHAR_BIT - BitsInCurWord;
118+
return uint64_t(NextChar)*CHAR_BIT - BitsInCurWord;
119119
}
120120

121121
// Return the byte # of the current bit.

llvm/include/llvm/Bitstream/BitstreamWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class BitstreamWriter {
111111
/// valid. Flushing only occurs at (sub)block boundaries.
112112
BitstreamWriter(SmallVectorImpl<char> &O, raw_fd_stream *FS = nullptr,
113113
uint32_t FlushThreshold = 512)
114-
: Out(O), FS(FS), FlushThreshold(FlushThreshold << 20), CurBit(0),
114+
: Out(O), FS(FS), FlushThreshold(uint64_t(FlushThreshold) << 20), CurBit(0),
115115
CurValue(0), CurCodeSize(2) {}
116116

117117
~BitstreamWriter() {

0 commit comments

Comments
 (0)