Fixed some arithmetic checks in Java and C code.

pull/16/head
Project Nayuki 7 years ago
parent f7888d5a24
commit 7e512971df

@ -346,7 +346,7 @@ static void encodeQrCodeTail(uint8_t dataAndQrcode[], int bitLen, uint8_t tempBu
// Appends the given sequence of bits to the given byte-based bit buffer, increasing the bit length.
testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) {
assert(0 <= numBits && numBits <= 16 && (long)val >> numBits == 0);
assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0);
for (int i = numBits - 1; i >= 0; i--, (*bitLen)++)
buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7));
}

@ -59,7 +59,7 @@ public final class BitBuffer implements Cloneable {
// Returns the bit at the given index, yielding 0 or 1, or throwing IndexOutOfBoundsException.
public int getBit(int index) {
if (index < 0 || index > bitLength)
if (index < 0 || index >= bitLength)
throw new IndexOutOfBoundsException();
return data.get(index) ? 1 : 0;
}

Loading…
Cancel
Save