diff options
author | Nathan Moinvaziri <nathan@nathanm.com> | 2020-06-28 13:05:11 -0700 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2020-07-01 23:06:53 +0200 |
commit | c611f608e8483906de1c3920b34dc8dbd1140ec2 (patch) | |
tree | 9eb1330c797471cf57c6417e814a930fce99acf7 /deflate.c | |
parent | d0e108b5703cf97104be0d3e58223ddf5a2150b5 (diff) |
Fixed bad shift operation warning in deflatePrime.
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.
Diffstat (limited to 'deflate.c')
-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; |