From 7e512971df6dd8d731a1992898784d02e0de8977 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 18 Aug 2017 03:31:35 +0000 Subject: [PATCH] Fixed some arithmetic checks in Java and C code. --- c/qrcodegen.c | 2 +- java/io/nayuki/qrcodegen/BitBuffer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index e162d1b..2374554 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -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)); } diff --git a/java/io/nayuki/qrcodegen/BitBuffer.java b/java/io/nayuki/qrcodegen/BitBuffer.java index 9302e67..961f804 100644 --- a/java/io/nayuki/qrcodegen/BitBuffer.java +++ b/java/io/nayuki/qrcodegen/BitBuffer.java @@ -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; }