mirror of
https://github.com/status-im/QR-Code-generator.git
synced 2025-02-24 10:28:20 +00:00
Simplified the argument check in BitBuffer.appendBits() by tightening the input range, also removed some parentheses.
This commit is contained in:
parent
7e512971df
commit
97e0388cb7
@ -39,7 +39,7 @@ std::vector<std::uint8_t> BitBuffer::getBytes() const {
|
||||
|
||||
|
||||
void BitBuffer::appendBits(std::uint32_t val, int len) {
|
||||
if (len < 0 || len > 32 || (len < 32 && (val >> len) != 0))
|
||||
if (len < 0 || len > 31 || val >> len != 0)
|
||||
throw "Value out of range";
|
||||
for (int i = len - 1; i >= 0; i--) // Append bit by bit
|
||||
this->push_back(((val >> i) & 1) != 0);
|
||||
|
@ -77,7 +77,7 @@ public final class BitBuffer implements Cloneable {
|
||||
// Appends the given number of bits of the given value to this sequence.
|
||||
// If 0 <= len <= 31, then this requires 0 <= val < 2^len.
|
||||
public void appendBits(int val, int len) {
|
||||
if (len < 0 || len > 32 || len < 32 && (val >>> len) != 0)
|
||||
if (len < 0 || len > 31 || val >>> len != 0)
|
||||
throw new IllegalArgumentException("Value out of range");
|
||||
for (int i = len - 1; i >= 0; i--, bitLength++) // Append bit by bit
|
||||
data.set(bitLength, ((val >>> i) & 1) != 0);
|
||||
|
@ -1006,7 +1006,7 @@ var qrcodegen = new function() {
|
||||
// Appends the given number of bits of the given value to this sequence.
|
||||
// If 0 <= len <= 31, then this requires 0 <= val < 2^len.
|
||||
this.appendBits = function(val, len) {
|
||||
if (len < 0 || len > 32 || len < 32 && (val >>> len) != 0)
|
||||
if (len < 0 || len > 31 || val >>> len != 0)
|
||||
throw "Value out of range";
|
||||
for (var i = len - 1; i >= 0; i--) // Append bit by bit
|
||||
this.push((val >>> i) & 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user