]> wimlib.net Git - wimlib/commitdiff
bitstream_put_bits(): Mask high-order bits
authorEric Biggers <ebiggers3@gmail.com>
Fri, 13 Dec 2013 16:29:35 +0000 (10:29 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 13 Dec 2013 16:29:35 +0000 (10:29 -0600)
src/compress.c
src/lzx-compress.c

index 14046b19463f9bb4c28935b41cd21310440bcc90..76043d632b98f6f3e670c948f5f09b8d62521d90 100644 (file)
@@ -41,6 +41,7 @@ void
 bitstream_put_bits(struct output_bitstream *ostream, u32 bits,
                   unsigned num_bits)
 {
 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
        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
index e34b320456e72325b95dbbc2adef7d6155603242..04e5fbfb6fe2f1d3e51ffac9cb8ad4d03b4ad638 100644 (file)
@@ -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, 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
        }
 
        /* Write out lengths of the main code. Note that the LZX specification