COMMON: Fix potential UB while shifting Common::BitStream
Shifting a 32-bit value by more than 31 is undefined.
This commit is contained in:
parent
eb8aee1335
commit
657ee2da59
1 changed files with 6 additions and 0 deletions
|
@ -176,6 +176,9 @@ public:
|
|||
|
||||
/** Read a multi-bit value from the bit stream. */
|
||||
uint32 getBits(uint8 n) {
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
if (n > 32)
|
||||
error("BitStreamImpl::getBits(): Too many bits requested to be read");
|
||||
|
||||
|
@ -225,6 +228,9 @@ public:
|
|||
|
||||
/** Add a bit to the value x, making it an n-bit value. */
|
||||
void addBit(uint32 &x, uint32 n) {
|
||||
if (n >= 32)
|
||||
error("BitStreamImpl::addBit(): Too many bits requested to be read");
|
||||
|
||||
if (isMSB2LSB)
|
||||
x = (x << 1) | getBit();
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue