]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use MIN and MAX macros.
authorNathan Moinvaziri <nathan@nathanm.com>
Sat, 5 Jun 2021 02:46:33 +0000 (19:46 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 13 Jun 2021 18:56:06 +0000 (20:56 +0200)
deflate.c
deflate_stored.c
infback.c
inflate.c
inftrees.c
zbuild.h

index 695822ec31bd1562fcffb6aa97a14519e32caa74..e512e5e9dfb1765149c136414d43d51dd3451f86 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -552,8 +552,8 @@ int32_t Z_EXPORT PREFIX(deflatePrime)(PREFIX3(stream) *strm, int32_t bits, int32
         return Z_BUF_ERROR;
     do {
         put = BIT_BUF_SIZE - s->bi_valid;
-        if (put > bits)
-            put = bits;
+        put = MIN(put, bits);
+
         if (s->bi_valid == 0)
             s->bi_buf = value64;
         else
@@ -1117,8 +1117,7 @@ int32_t Z_EXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
 Z_INTERNAL unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
     uint32_t len = strm->avail_in;
 
-    if (len > size)
-        len = size;
+    len = MIN(len, size);
     if (len == 0)
         return 0;
 
index 860d894ddd923754d1aea1ea2de93f4989fa8f8a..92e57fad805640b465e435dca45d43b655da12b4 100644 (file)
@@ -132,7 +132,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
         }
         s->block_start = (int)s->strstart;
     }
-    s->high_water = MIN(s->high_water, s->strstart);
+    s->high_water = MAX(s->high_water, s->strstart);
 
     /* If the last block was written to next_out, then done. */
     if (last)
@@ -161,7 +161,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
         s->strstart += have;
         s->insert += MIN(have, s->w_size - s->insert);
     }
-    s->high_water = MIN(s->high_water, s->strstart);
+    s->high_water = MAX(s->high_water, s->strstart);
 
     /* There was not enough avail_out to write a complete worthy or flushed
      * stored block to next_out. Write a stored block to pending instead, if we
index 62369396ffd07921bd585d1433897d0a73a1a6bd..cab3f66cf69afd09637c1abd86a43de5812521e7 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -210,8 +210,8 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
                 copy = state->length;
                 PULL();
                 ROOM();
-                if (copy > have) copy = have;
-                if (copy > left) copy = left;
+                copy = MIN(copy, have);
+                copy = MIN(copy, left);
                 memcpy(put, next, copy);
                 have -= copy;
                 next += copy;
@@ -453,8 +453,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
                     from = put - state->offset;
                     copy = left;
                 }
-                if (copy > state->length)
-                    copy = state->length;
+                copy = MIN(copy, state->length);
                 state->length -= copy;
                 left -= copy;
                 do {
index 5c30816ddfd53a687da8765b3059323d088e24aa..e2a6f2c6965758ff02ca439256182a8387c94482 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -657,8 +657,8 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
             /* copy stored block from input to output */
             copy = state->length;
             if (copy) {
-                if (copy > have) copy = have;
-                if (copy > left) copy = left;
+                copy = MIN(copy, have);
+                copy = MIN(copy, left);
                 if (copy == 0) goto inf_leave;
                 memcpy(put, next, copy);
                 have -= copy;
@@ -928,10 +928,8 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
                     Trace((stderr, "inflate.c too far\n"));
                     copy -= state->whave;
-                    if (copy > state->length)
-                        copy = state->length;
-                    if (copy > left)
-                        copy = left;
+                    copy = MIN(copy, state->length);
+                    copy = MIN(copy, left);
                     left -= copy;
                     state->length -= copy;
                     do {
@@ -948,16 +946,12 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
                 } else {
                     from = state->window + (state->wnext - copy);
                 }
-                if (copy > state->length)
-                    copy = state->length;
-                if (copy > left)
-                    copy = left;
+                copy = MIN(copy, state->length);
+                copy = MIN(copy, left);
 
                 put = functable.chunkcopy_safe(put, from, copy, put + left);
             } else {                             /* copy from output */
-                copy = state->length;
-                if (copy > left)
-                    copy = left;
+                copy = MIN(state->length, left);
 
                 put = functable.chunkmemset_safe(put, state->offset, copy, left);
             }
index faf1d249d65313fa0679b9180a0a6c372769031d..136e25c2b154813a09d5003a292bc6b40520c6d8 100644 (file)
@@ -107,7 +107,7 @@ int Z_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
     root = *bits;
     for (max = MAXBITS; max >= 1; max--)
         if (count[max] != 0) break;
-    if (root > max) root = max;
+    root = MIN(root, max);
     if (max == 0) {                     /* no symbols to code at all */
         here.op = (unsigned char)64;    /* invalid code marker */
         here.bits = (unsigned char)1;
@@ -119,7 +119,7 @@ int Z_INTERNAL zng_inflate_table(codetype type, uint16_t *lens, unsigned codes,
     }
     for (min = 1; min < max; min++)
         if (count[min] != 0) break;
-    if (root < min) root = min;
+    root = MAX(root, min);
 
     /* check for an over-subscribed or incomplete set of lengths */
     left = 1;
index c68fb109e41ce53c39762c299f20d055a8ea2fd2..87b7426ab4b55f95b0c7cf148a857dedc2e51a75 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
@@ -28,5 +28,7 @@
 
 /* Minimum of a and b. */
 #define MIN(a, b) ((a) > (b) ? (b) : (a))
+/* Maximum of a and b. */
+#define MAX(a, b) ((a) < (b) ? (b) : (a))
 
 #endif