From f56a369ab08fe8966d7e629c89c0c9e7fb1bd33c Mon Sep 17 00:00:00 2001 From: James Zern Date: Sun, 1 Jul 2012 13:49:44 -0700 Subject: [PATCH] fix big-endian VP8LWriteBits bits would be lost if n_bits was > 17 Change-Id: Id315d075075338a08e10c04faa91cab347a53591 --- src/utils/bit_writer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/bit_writer.c b/src/utils/bit_writer.c index 260ad89e..fcb0a3c9 100644 --- a/src/utils/bit_writer.c +++ b/src/utils/bit_writer.c @@ -230,7 +230,7 @@ void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits) { if (n_bits < 1) return; #if !defined(__BIG_ENDIAN__) // Technically, this branch of the code can write up to 25 bits at a time, - // but in deflate, the maximum number of bits written is 16 at a time. + // but in prefix encoding, the maximum number of bits written is 18 at a time. { uint8_t* p = &bw->buf_[bw->bit_pos_ >> 3]; uint32_t v = *(const uint32_t*)(p); @@ -251,7 +251,8 @@ void VP8LWriteBits(VP8LBitWriter* const bw, int n_bits, uint32_t bits) { *p++ = bits >> (16 - bits_reserved_in_first_byte); } } - *p = 0; + assert(n_bits <= 25); + *p = bits >> (24 - bits_reserved_in_first_byte); bw->bit_pos_ += n_bits; } #endif // BIG_ENDIAN