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
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;
}
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)
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
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;
from = put - state->offset;
copy = left;
}
- if (copy > state->length)
- copy = state->length;
+ copy = MIN(copy, state->length);
state->length -= copy;
left -= copy;
do {
/* 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;
#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 {
} 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);
}
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;
}
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;
/* 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