From: Nathan Moinvaziri Date: Sat, 5 Jun 2021 02:46:33 +0000 (-0700) Subject: Use MIN and MAX macros. X-Git-Tag: 2.1.0-beta1~572 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f5801f151ce9ab74664e9b286ad3edaa5b12d7e;p=thirdparty%2Fzlib-ng.git Use MIN and MAX macros. --- diff --git a/deflate.c b/deflate.c index 695822ec..e512e5e9 100644 --- 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; diff --git a/deflate_stored.c b/deflate_stored.c index 860d894d..92e57fad 100644 --- a/deflate_stored.c +++ b/deflate_stored.c @@ -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 diff --git a/infback.c b/infback.c index 62369396..cab3f66c 100644 --- 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 { diff --git a/inflate.c b/inflate.c index 5c30816d..e2a6f2c6 100644 --- 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); } diff --git a/inftrees.c b/inftrees.c index faf1d249..136e25c2 100644 --- a/inftrees.c +++ b/inftrees.c @@ -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; diff --git a/zbuild.h b/zbuild.h index c68fb109..87b7426a 100644 --- 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