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

pull/11/head
Project Nayuki 8 years ago
parent 3da7c7b7dc
commit a9c12dd705

@ -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)

Loading…
Cancel
Save