From a9c12dd70531e1f14e9a6ba3079efcb3a742cb1d Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 24 Apr 2017 20:48:14 +0000 Subject: [PATCH] Rearranged some overflow comparisons in C++ code for clarity, without changing behavior. --- cpp/BitBuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/BitBuffer.cpp b/cpp/BitBuffer.cpp index a2e59b5..e9cde17 100644 --- a/cpp/BitBuffer.cpp +++ b/cpp/BitBuffer.cpp @@ -46,7 +46,7 @@ std::vector BitBuffer::getBytes() const { void BitBuffer::appendBits(uint32_t val, int len) { if (len < 0 || len > 32 || (len < 32 && (val >> len) != 0)) throw "Value out of range"; - if (INT_MAX - bitLength < len) + if (len > INT_MAX - bitLength) throw "Buffer too long"; unsigned int newByteLen = ((unsigned int)bitLength + len + 7) / 8; while (data.size() < newByteLen) @@ -57,7 +57,7 @@ void BitBuffer::appendBits(uint32_t val, int len) { void BitBuffer::appendData(const QrSegment &seg) { - if (INT_MAX - bitLength < seg.bitLength) + if (seg.bitLength > INT_MAX - bitLength) throw "Buffer too long"; unsigned int newByteLen = ((unsigned int)bitLength + seg.bitLength + 7) / 8; while (data.size() < newByteLen)