Rearranged some overflow comparisons in C++ code for clarity, without changing behavior.

This commit is contained in:
Project Nayuki 2017-04-24 20:48:14 +00:00
parent 3da7c7b7dc
commit a9c12dd705
1 changed files with 2 additions and 2 deletions

View File

@ -46,7 +46,7 @@ std::vector<uint8_t> BitBuffer::getBytes() const {
void BitBuffer::appendBits(uint32_t val, int len) { void BitBuffer::appendBits(uint32_t val, int len) {
if (len < 0 || len > 32 || (len < 32 && (val >> len) != 0)) if (len < 0 || len > 32 || (len < 32 && (val >> len) != 0))
throw "Value out of range"; throw "Value out of range";
if (INT_MAX - bitLength < len) if (len > INT_MAX - bitLength)
throw "Buffer too long"; throw "Buffer too long";
unsigned int newByteLen = ((unsigned int)bitLength + len + 7) / 8; unsigned int newByteLen = ((unsigned int)bitLength + len + 7) / 8;
while (data.size() < newByteLen) while (data.size() < newByteLen)
@ -57,7 +57,7 @@ void BitBuffer::appendBits(uint32_t val, int len) {
void BitBuffer::appendData(const QrSegment &seg) { void BitBuffer::appendData(const QrSegment &seg) {
if (INT_MAX - bitLength < seg.bitLength) if (seg.bitLength > INT_MAX - bitLength)
throw "Buffer too long"; throw "Buffer too long";
unsigned int newByteLen = ((unsigned int)bitLength + seg.bitLength + 7) / 8; unsigned int newByteLen = ((unsigned int)bitLength + seg.bitLength + 7) / 8;
while (data.size() < newByteLen) while (data.size() < newByteLen)