aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSven Hesse2011-10-20 20:47:53 +0200
committerSven Hesse2011-10-21 00:19:02 +0200
commit657ee2da596a783b6df1c5d056bf982435ed39e8 (patch)
tree2bf1644791602fd2c30896ce60045e76c2415315 /common
parenteb8aee13357c8eb556b1d4b0c37ef2b804ff0b80 (diff)
downloadscummvm-rg350-657ee2da596a783b6df1c5d056bf982435ed39e8.tar.gz
scummvm-rg350-657ee2da596a783b6df1c5d056bf982435ed39e8.tar.bz2
scummvm-rg350-657ee2da596a783b6df1c5d056bf982435ed39e8.zip
COMMON: Fix potential UB while shifting Common::BitStream
Shifting a 32-bit value by more than 31 is undefined.
Diffstat (limited to 'common')
-rw-r--r--common/bitstream.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/common/bitstream.h b/common/bitstream.h
index 34063dbfe1..61ec4abc76 100644
--- a/common/bitstream.h
+++ b/common/bitstream.h
@@ -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