From: Nathan Moinvaziri Date: Fri, 1 Mar 2019 10:44:37 +0000 (-0800) Subject: Fixed arithmetic overflow warnings on Windows (#302) X-Git-Tag: 1.9.9-b1~521 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5deeb8367fbe260fb44e403a56b1c6eee94857af;p=thirdparty%2Fzlib-ng.git Fixed arithmetic overflow warnings on Windows (#302) Fixed arithmetic overflow warnings in MSVC. Fixed uint64_t to uint32_t casting warning. Added assert to check if bits is greater than 32 before cast. --- diff --git a/inffast.c b/inffast.c index 34f0b8bd..5e965681 100644 --- a/inffast.c +++ b/inffast.c @@ -12,7 +12,7 @@ /* Return the low n bits of the bit accumulator (n < 16) */ #define BITS(n) \ - (hold & ((1U << (n)) - 1)) + (hold & ((UINT64_C(1) << (n)) - 1)) /* Remove n bits from the bit accumulator */ #define DROPBITS(n) \ @@ -447,7 +447,7 @@ void ZLIB_INTERNAL inflate_fast(PREFIX3(stream) *strm, unsigned long start) { len = bits >> 3; in -= len; bits -= len << 3; - hold &= (1U << bits) - 1; + hold &= (UINT64_C(1) << bits) - 1; /* update state and return */ strm->next_in = in; @@ -458,7 +458,9 @@ void ZLIB_INTERNAL inflate_fast(PREFIX3(stream) *strm, unsigned long start) { strm->avail_out = (unsigned)(out < end ? (INFLATE_FAST_MIN_LEFT - 1) + (end - out) : (INFLATE_FAST_MIN_LEFT - 1) - (out - end)); - state->hold = hold; + + Assert(bits <= 32, "Remaining bits greater than 32"); + state->hold = (uint32_t)hold; state->bits = bits; return; }