From dce44caf8f677156e88d78d4e8b56ef19ed07f4e Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Tue, 2 Oct 2018 08:55:34 +0000 Subject: [PATCH] Tweaked BitBuffer.appendBits() comment in several language versions. --- c/qrcodegen.c | 1 + cpp/BitBuffer.hpp | 2 +- rust/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 998e13a..ffdd9bd 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -177,6 +177,7 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod // Appends the given sequence of bits to the given byte-based bit buffer, increasing the bit length. +// Requires 0 <= numBits <= 16 and 0 <= val < 2^numBits. testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) { assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0); for (int i = numBits - 1; i >= 0; i--, (*bitLen)++) diff --git a/cpp/BitBuffer.hpp b/cpp/BitBuffer.hpp index 2e6d734..436773b 100644 --- a/cpp/BitBuffer.hpp +++ b/cpp/BitBuffer.hpp @@ -49,7 +49,7 @@ class BitBuffer final : public std::vector { // Appends the given number of low bits of the given value - // to this sequence. Requires 0 <= val < 2^len. + // to this sequence. Requires 0 <= len <= 31 and 0 <= val < 2^len. public: void appendBits(std::uint32_t val, int len); }; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7a34831..3f42530 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1065,7 +1065,7 @@ pub struct BitBuffer(pub Vec); impl BitBuffer { // Appends the given number of low bits of the given value - // to this sequence. Requires 0 <= val < 2^len. + // to this sequence. Requires 0 <= len <= 31 and 0 <= val < 2^len. pub fn append_bits(&mut self, val: u32, len: u8) { assert!(len < 32 && (val >> len) == 0 || len == 32, "Value out of range"); self.0.extend((0 .. len as i32).rev().map(|i| get_bit(val, i))); // Append bit by bit