diff options
-rw-r--r-- | deflate.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -586,14 +586,17 @@ int32_t ZEXPORT PREFIX(deflatePrime)(PREFIX3(stream) *strm, int32_t bits, int32_ if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; - if (bits < 0 || bits > BIT_BUF_SIZE || + if (bits < 0 || bits > BIT_BUF_SIZE || bits > (sizeof(value) << 3) || s->sym_buf < s->pending_out + ((BIT_BUF_SIZE + 7) >> 3)) return Z_BUF_ERROR; do { put = BIT_BUF_SIZE - s->bi_valid; if (put > bits) put = bits; - s->bi_buf |= (((uint64_t)value & ((UINT64_C(1) << put) - 1)) << s->bi_valid); + if (s->bi_valid == 0) + s->bi_buf = (uint64_t)value; + else + s->bi_buf |= (((uint64_t)value & ((UINT64_C(1) << put) - 1)) << s->bi_valid); s->bi_valid += put; zng_tr_flush_bits(s); value >>= put; |