From 4ecf344e77e1f5891055881950a6e89e32b16008 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Fri, 13 Dec 2013 10:29:35 -0600 Subject: [PATCH 1/1] bitstream_put_bits(): Mask high-order bits --- src/compress.c | 1 + src/lzx-compress.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compress.c b/src/compress.c index 14046b19..76043d63 100644 --- a/src/compress.c +++ b/src/compress.c @@ -41,6 +41,7 @@ void bitstream_put_bits(struct output_bitstream *ostream, u32 bits, unsigned num_bits) { + bits &= (1U << num_bits) - 1; while (num_bits > ostream->free_bits) { /* Buffer variable does not have space for the new bits. It * needs to be flushed as a 16-bit integer. Bits in the second diff --git a/src/lzx-compress.c b/src/lzx-compress.c index e34b3204..04e5fbfb 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -984,9 +984,9 @@ lzx_write_compressed_block(int block_type, bitstream_put_bits(ostream, 0, 1); if (max_window_size >= 65536) - bitstream_put_bits(ostream, (block_size >> 16) & 0xff, 8); + bitstream_put_bits(ostream, block_size >> 16, 8); - bitstream_put_bits(ostream, block_size & 0xffff, 16); + bitstream_put_bits(ostream, block_size, 16); } /* Write out lengths of the main code. Note that the LZX specification -- 2.43.0