From 3da7c7b7dcf10687e75639bf435cb61ffcf173f2 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 24 Apr 2017 20:47:32 +0000 Subject: [PATCH] Fixed potential overflow in C++ code, in worst case when int type is int16. --- cpp/QrSegment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index f96ec1a..cd514d5 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -141,7 +141,7 @@ int QrSegment::getTotalBits(const std::vector &segs, int version) { const QrSegment &seg(segs.at(i)); int ccbits = seg.mode.numCharCountBits(version); // Fail if segment length value doesn't fit in the length field's bit-width - if ((unsigned int)seg.numChars >= (1U << ccbits) || seg.bitLength > INT16_MAX) + if (seg.numChars >= (1L << ccbits) || seg.bitLength > INT16_MAX) return -1; long temp = (long)result + 4 + ccbits + seg.bitLength; if (temp > INT_MAX)