]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fixed arithmetic overflow warnings on Windows (#302)
authorNathan Moinvaziri <nathan@nathanm.com>
Fri, 1 Mar 2019 10:44:37 +0000 (02:44 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 1 Mar 2019 10:44:37 +0000 (11:44 +0100)
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.

inffast.c

index 34f0b8bd6120019120de6e5535ff09178485bd2c..5e9656811df67f871c794e72bc43e79937f60b94 100644 (file)
--- 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;
 }