Check that bits value is not greater than bits allowed by value type.
CID 293475 (#2-4 of 4): Bad bit shift operation (BAD_SHIFT)
In expression 1UL << put, left shifting by more than 63 bits has undefined behavior.
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;