diff --git a/src/io/nayuki/fastqrcodegen/QrCode.java b/src/io/nayuki/fastqrcodegen/QrCode.java index 3390eb2..61f37c8 100644 --- a/src/io/nayuki/fastqrcodegen/QrCode.java +++ b/src/io/nayuki/fastqrcodegen/QrCode.java @@ -297,7 +297,7 @@ public final class QrCode { byte[] ecc = new byte[blockEccLen]; // Temporary storage per iteration for (int i = 0, k = 0; i < numBlocks; i++) { int datLen = shortBlockDataLen + (i < numShortBlocks ? 0 : 1); - rs.getRemainder(data, k, datLen, ecc, 0); + rs.getRemainder(data, k, datLen, ecc); for (int j = 0, l = i; j < datLen; j++, k++, l += numBlocks) { // Copy data if (j == shortBlockDataLen) l -= numShortBlocks; diff --git a/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java b/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java index 99ba41b..aef45c0 100644 --- a/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java +++ b/src/io/nayuki/fastqrcodegen/ReedSolomonGenerator.java @@ -122,19 +122,19 @@ final class ReedSolomonGenerator { } - public void getRemainder(byte[] data, int dataOff, int dataLen, byte[] result, int resultOff) { + public void getRemainder(byte[] data, int dataOff, int dataLen, byte[] result) { Objects.requireNonNull(data); Objects.requireNonNull(result); + int degree = polynomialMultiply[0].length; + assert result.length == degree; // Compute the remainder by performing polynomial division - int degree = polynomialMultiply[0].length; - int resultEnd = resultOff + degree; - Arrays.fill(result, resultOff, resultEnd, (byte)0); + Arrays.fill(result, (byte)0); for (int i = dataOff, dataEnd = dataOff + dataLen; i < dataEnd; i++) { - byte[] table = polynomialMultiply[(data[i] ^ result[resultOff]) & 0xFF]; + byte[] table = polynomialMultiply[(data[i] ^ result[0]) & 0xFF]; for (int j = 0; j < degree - 1; j++) - result[resultOff + j] = (byte)(result[resultOff + j + 1] ^ table[j]); - result[resultOff + degree - 1] = table[degree - 1]; + result[j] = (byte)(result[j + 1] ^ table[j]); + result[degree - 1] = table[degree - 1]; } }