Fixed potential overflow in C++ code, in worst case when int type is int16.

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

@ -141,7 +141,7 @@ int QrSegment::getTotalBits(const std::vector<QrSegment> &segs, int version) {
const QrSegment &seg(segs.at(i)); const QrSegment &seg(segs.at(i));
int ccbits = seg.mode.numCharCountBits(version); int ccbits = seg.mode.numCharCountBits(version);
// Fail if segment length value doesn't fit in the length field's bit-width // 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; return -1;
long temp = (long)result + 4 + ccbits + seg.bitLength; long temp = (long)result + 4 + ccbits + seg.bitLength;
if (temp > INT_MAX) if (temp > INT_MAX)

Loading…
Cancel
Save