diff --git a/c/qrcodegen.c b/c/qrcodegen.c index fceae70..112e974 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -437,25 +437,24 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >> 9) * 0x537); - data = data << 10 | rem; - data ^= 0x5412; // uint15 - assert(data >> 15 == 0); + int bits = (data << 10 | rem) ^ 0x5412; // uint15 + assert(bits >> 15 == 0); // Draw first copy for (int i = 0; i <= 5; i++) - setModule(qrcode, 8, i, getBit(data, i)); - setModule(qrcode, 8, 7, getBit(data, 6)); - setModule(qrcode, 8, 8, getBit(data, 7)); - setModule(qrcode, 7, 8, getBit(data, 8)); + setModule(qrcode, 8, i, getBit(bits, i)); + setModule(qrcode, 8, 7, getBit(bits, 6)); + setModule(qrcode, 8, 8, getBit(bits, 7)); + setModule(qrcode, 7, 8, getBit(bits, 8)); for (int i = 9; i < 15; i++) - setModule(qrcode, 14 - i, 8, getBit(data, i)); + setModule(qrcode, 14 - i, 8, getBit(bits, i)); // Draw second copy int qrsize = qrcodegen_getSize(qrcode); for (int i = 0; i <= 7; i++) - setModule(qrcode, qrsize - 1 - i, 8, getBit(data, i)); + setModule(qrcode, qrsize - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) - setModule(qrcode, 8, qrsize - 15 + i, getBit(data, i)); + setModule(qrcode, 8, qrsize - 15 + i, getBit(bits, i)); setModule(qrcode, 8, qrsize - 8, true); // Always black } diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 369529c..668bdb9 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -222,25 +222,24 @@ void QrCode::drawFormatBits(int mask) { int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >> 9) * 0x537); - data = data << 10 | rem; - data ^= 0x5412; // uint15 - if (data >> 15 != 0) + int bits = (data << 10 | rem) ^ 0x5412; // uint15 + if (bits >> 15 != 0) throw std::logic_error("Assertion error"); // Draw first copy for (int i = 0; i <= 5; i++) - setFunctionModule(8, i, getBit(data, i)); - setFunctionModule(8, 7, getBit(data, 6)); - setFunctionModule(8, 8, getBit(data, 7)); - setFunctionModule(7, 8, getBit(data, 8)); + setFunctionModule(8, i, getBit(bits, i)); + setFunctionModule(8, 7, getBit(bits, 6)); + setFunctionModule(8, 8, getBit(bits, 7)); + setFunctionModule(7, 8, getBit(bits, 8)); for (int i = 9; i < 15; i++) - setFunctionModule(14 - i, 8, getBit(data, i)); + setFunctionModule(14 - i, 8, getBit(bits, i)); // Draw second copy for (int i = 0; i <= 7; i++) - setFunctionModule(size - 1 - i, 8, getBit(data, i)); + setFunctionModule(size - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) - setFunctionModule(8, size - 15 + i, getBit(data, i)); + setFunctionModule(8, size - 15 + i, getBit(bits, i)); setFunctionModule(8, size - 8, true); // Always black } diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 7d62e0a..8a551b1 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -351,24 +351,23 @@ public final class QrCode { int rem = data; for (int i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); - data = data << 10 | rem; - data ^= 0x5412; // uint15 - assert data >>> 15 == 0; + int bits = (data << 10 | rem) ^ 0x5412; // uint15 + assert bits >>> 15 == 0; // Draw first copy for (int i = 0; i <= 5; i++) - setFunctionModule(8, i, getBit(data, i)); - setFunctionModule(8, 7, getBit(data, 6)); - setFunctionModule(8, 8, getBit(data, 7)); - setFunctionModule(7, 8, getBit(data, 8)); + setFunctionModule(8, i, getBit(bits, i)); + setFunctionModule(8, 7, getBit(bits, 6)); + setFunctionModule(8, 8, getBit(bits, 7)); + setFunctionModule(7, 8, getBit(bits, 8)); for (int i = 9; i < 15; i++) - setFunctionModule(14 - i, 8, getBit(data, i)); + setFunctionModule(14 - i, 8, getBit(bits, i)); // Draw second copy for (int i = 0; i <= 7; i++) - setFunctionModule(size - 1 - i, 8, getBit(data, i)); + setFunctionModule(size - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) - setFunctionModule(8, size - 15 + i, getBit(data, i)); + setFunctionModule(8, size - 15 + i, getBit(bits, i)); setFunctionModule(8, size - 8, true); // Always black } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 603a41c..36a0384 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -227,25 +227,24 @@ var qrcodegen = new function() { var rem = data; for (var i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); - data = data << 10 | rem; - data ^= 0x5412; // uint15 - if (data >>> 15 != 0) + var bits = (data << 10 | rem) ^ 0x5412; // uint15 + if (bits >>> 15 != 0) throw "Assertion error"; // Draw first copy for (var i = 0; i <= 5; i++) - setFunctionModule(8, i, getBit(data, i)); - setFunctionModule(8, 7, getBit(data, 6)); - setFunctionModule(8, 8, getBit(data, 7)); - setFunctionModule(7, 8, getBit(data, 8)); + setFunctionModule(8, i, getBit(bits, i)); + setFunctionModule(8, 7, getBit(bits, 6)); + setFunctionModule(8, 8, getBit(bits, 7)); + setFunctionModule(7, 8, getBit(bits, 8)); for (var i = 9; i < 15; i++) - setFunctionModule(14 - i, 8, getBit(data, i)); + setFunctionModule(14 - i, 8, getBit(bits, i)); // Draw second copy for (var i = 0; i <= 7; i++) - setFunctionModule(size - 1 - i, 8, getBit(data, i)); + setFunctionModule(size - 1 - i, 8, getBit(bits, i)); for (var i = 8; i < 15; i++) - setFunctionModule(8, size - 15 + i, getBit(data, i)); + setFunctionModule(8, size - 15 + i, getBit(bits, i)); setFunctionModule(8, size - 8, true); // Always black } diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 2e19aed..8f0fbdb 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -274,24 +274,23 @@ class QrCode(object): rem = data for _ in range(10): rem = (rem << 1) ^ ((rem >> 9) * 0x537) - data = data << 10 | rem - data ^= 0x5412 # uint15 - assert data >> 15 == 0 + bits = (data << 10 | rem) ^ 0x5412 # uint15 + assert bits >> 15 == 0 # Draw first copy for i in range(0, 6): - self._set_function_module(8, i, _get_bit(data, i)) - self._set_function_module(8, 7, _get_bit(data, 6)) - self._set_function_module(8, 8, _get_bit(data, 7)) - self._set_function_module(7, 8, _get_bit(data, 8)) + self._set_function_module(8, i, _get_bit(bits, i)) + self._set_function_module(8, 7, _get_bit(bits, 6)) + self._set_function_module(8, 8, _get_bit(bits, 7)) + self._set_function_module(7, 8, _get_bit(bits, 8)) for i in range(9, 15): - self._set_function_module(14 - i, 8, _get_bit(data, i)) + self._set_function_module(14 - i, 8, _get_bit(bits, i)) # Draw second copy for i in range(0, 8): - self._set_function_module(self._size - 1 - i, 8, _get_bit(data, i)) + self._set_function_module(self._size - 1 - i, 8, _get_bit(bits, i)) for i in range(8, 15): - self._set_function_module(8, self._size - 15 + i, _get_bit(data, i)) + self._set_function_module(8, self._size - 15 + i, _get_bit(bits, i)) self._set_function_module(8, self._size - 8, True) # Always black diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8fe722c..dbeec47 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -313,27 +313,26 @@ impl QrCode { for _ in 0 .. 10 { rem = (rem << 1) ^ ((rem >> 9) * 0x537); } - data = data << 10 | rem; - data ^= 0x5412; // uint15 - assert_eq!(data >> 15, 0, "Assertion error"); + let bits: u32 = (data << 10 | rem) ^ 0x5412; // uint15 + assert_eq!(bits >> 15, 0, "Assertion error"); // Draw first copy for i in 0 .. 6 { - self.set_function_module(8, i, get_bit(data, i)); + self.set_function_module(8, i, get_bit(bits, i)); } - self.set_function_module(8, 7, get_bit(data, 6)); - self.set_function_module(8, 8, get_bit(data, 7)); - self.set_function_module(7, 8, get_bit(data, 8)); + self.set_function_module(8, 7, get_bit(bits, 6)); + self.set_function_module(8, 8, get_bit(bits, 7)); + self.set_function_module(7, 8, get_bit(bits, 8)); for i in 9 .. 15 { - self.set_function_module(14 - i, 8, get_bit(data, i)); + self.set_function_module(14 - i, 8, get_bit(bits, i)); } // Draw second copy for i in 0 .. 8 { - self.set_function_module(size - 1 - i, 8, get_bit(data, i)); + self.set_function_module(size - 1 - i, 8, get_bit(bits, i)); } for i in 8 .. 15 { - self.set_function_module(8, size - 15 + i, get_bit(data, i)); + self.set_function_module(8, size - 15 + i, get_bit(bits, i)); } self.set_function_module(8, size - 8, true); // Always black } diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index bd0fd10..0101a46 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -290,25 +290,24 @@ namespace qrcodegen { let rem: int = data; for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); - data = data << 10 | rem; - data ^= 0x5412; // uint15 - if (data >>> 15 != 0) + let bits = (data << 10 | rem) ^ 0x5412; // uint15 + if (bits >>> 15 != 0) throw "Assertion error"; // Draw first copy for (let i = 0; i <= 5; i++) - this.setFunctionModule(8, i, getBit(data, i)); - this.setFunctionModule(8, 7, getBit(data, 6)); - this.setFunctionModule(8, 8, getBit(data, 7)); - this.setFunctionModule(7, 8, getBit(data, 8)); + this.setFunctionModule(8, i, getBit(bits, i)); + this.setFunctionModule(8, 7, getBit(bits, 6)); + this.setFunctionModule(8, 8, getBit(bits, 7)); + this.setFunctionModule(7, 8, getBit(bits, 8)); for (let i = 9; i < 15; i++) - this.setFunctionModule(14 - i, 8, getBit(data, i)); + this.setFunctionModule(14 - i, 8, getBit(bits, i)); // Draw second copy for (let i = 0; i <= 7; i++) - this.setFunctionModule(this.size - 1 - i, 8, getBit(data, i)); + this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i)); for (let i = 8; i < 15; i++) - this.setFunctionModule(8, this.size - 15 + i, getBit(data, i)); + this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i)); this.setFunctionModule(8, this.size - 8, true); // Always black }