}
if (strm->zfree == NULL)
strm->zfree = zng_cfree;
- state = (struct inflate_state *)ZALLOC(strm, 1, sizeof(struct inflate_state));
+ state = (struct inflate_state *) ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == NULL)
return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
copy = state->length;
PULL();
ROOM();
- if (copy > have)
- copy = have;
- if (copy > left)
- copy = left;
+ if (copy > have) copy = have;
+ if (copy > left) copy = left;
memcpy(put, next, copy);
have -= copy;
next += copy;
}
#endif
Tracev((stderr, "inflate: table sizes ok\n"));
+ state->have = 0;
/* get code length code lengths (not a typo) */
- state->have = 0;
while (state->have < state->ncode) {
NEEDBITS(3);
state->lens[order[state->have++]] = (uint16_t)BITS(3);
while (state->have < 19)
state->lens[order[state->have++]] = 0;
state->next = state->codes;
- state->lencode = (code const *)(state->next);
+ state->lencode = (const code *)(state->next);
state->lenbits = 7;
ret = zng_inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work);
if (ret) {
break;
}
Tracev((stderr, "inflate: code lengths ok\n"));
+ state->have = 0;
/* get length and distance code code lengths */
- state->have = 0;
while (state->have < state->nlen + state->ndist) {
for (;;) {
here = state->lencode[BITS(state->lenbits)];
- if (here.bits <= bits)
- break;
+ if (here.bits <= bits) break;
PULLBYTE();
}
if (here.val < 16) {
state->mode = BAD;
break;
}
- len = (unsigned)(state->lens[state->have - 1]);
+ len = state->lens[state->have - 1];
copy = 3 + BITS(2);
DROPBITS(2);
} else if (here.val == 17) {
state->mode = BAD;
break;
}
- while (copy--)
+ while (copy) {
+ --copy;
state->lens[state->have++] = (uint16_t)len;
+ }
}
}
values here (9 and 6) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */
state->next = state->codes;
- state->lencode = (code const *)(state->next);
+ state->lencode = (const code *)(state->next);
state->lenbits = 9;
ret = zng_inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work);
if (ret) {
state->mode = BAD;
break;
}
- state->distcode = (code const *)(state->next);
+ state->distcode = (const code *)(state->next);
state->distbits = 6;
ret = zng_inflate_table(DISTS, state->lens + state->nlen, state->ndist,
&(state->next), &(state->distbits), state->work);
if (here.op && (here.op & 0xf0) == 0) {
last = here;
for (;;) {
- here = state->lencode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
+ here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)];
if ((unsigned)last.bits + (unsigned)here.bits <= bits)
break;
PULLBYTE();
state->length = here.val;
/* process literal */
- if (here.op == 0) {
+ if ((int)(here.op) == 0) {
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", here.val));
/* length code -- get extra bits, if any */
state->extra = (here.op & 15);
- if (state->extra != 0) {
+ if (state->extra) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
DROPBITS(state->extra);
break;
}
state->offset = here.val;
+ state->extra = (here.op & 15);
/* get distance extra bits, if any */
- state->extra = (here.op & 15);
- if (state->extra != 0) {
+ if (state->extra) {
NEEDBITS(state->extra);
state->offset += BITS(state->extra);
DROPBITS(state->extra);
}
+#ifdef INFLATE_STRICT
if (state->offset > state->wsize - (state->whave < state->wsize ? left : 0)) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
}
+#endif
Tracevv((stderr, "inflate: distance %u\n", state->offset));
/* copy match from window to output */
INITBITS();
break;
#ifdef GUNZIP
+
case FLAGS:
NEEDBITS(16);
state->flags = (int)(hold);
CRC2(state->check, hold);
INITBITS();
state->mode = TIME;
+
case TIME:
NEEDBITS(32);
if (state->head != NULL)
CRC4(state->check, hold);
INITBITS();
state->mode = OS;
+
case OS:
NEEDBITS(16);
if (state->head != NULL) {
CRC2(state->check, hold);
INITBITS();
state->mode = EXLEN;
+
case EXLEN:
if (state->flags & 0x0400) {
NEEDBITS(16);
state->head->extra = NULL;
}
state->mode = EXTRA;
+
case EXTRA:
if (state->flags & 0x0400) {
copy = state->length;
}
state->length = 0;
state->mode = NAME;
+
case NAME:
if (state->flags & 0x0800) {
if (have == 0) goto inf_leave;
}
state->length = 0;
state->mode = COMMENT;
+
case COMMENT:
if (state->flags & 0x1000) {
if (have == 0) goto inf_leave;
state->head->comment = NULL;
}
state->mode = HCRC;
+
case HCRC:
if (state->flags & 0x0200) {
NEEDBITS(16);
strm->adler = state->check = ZSWAP32(hold);
INITBITS();
state->mode = DICT;
+
case DICT:
if (state->havedict == 0) {
RESTORE();
}
strm->adler = state->check = functable.adler32(0L, NULL, 0);
state->mode = TYPE;
+
case TYPE:
if (flush == Z_BLOCK || flush == Z_TREES)
goto inf_leave;
+
case TYPEDO:
+ /* determine and dispatch block type */
INFLATE_TYPEDO_HOOK(strm, flush); /* hook for IBM Z DFLTCC */
if (state->last) {
BYTEBITS();
}
DROPBITS(2);
break;
+
case STORED:
+ /* get and verify stored block length */
BYTEBITS(); /* go to byte boundary */
NEEDBITS(32);
if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
state->mode = COPY_;
if (flush == Z_TREES)
goto inf_leave;
+
case COPY_:
state->mode = COPY;
+
case COPY:
+ /* copy stored block from input to output */
copy = state->length;
if (copy) {
if (copy > have) copy = have;
Tracev((stderr, "inflate: stored end\n"));
state->mode = TYPE;
break;
+
case TABLE:
+ /* get dynamic table entries descriptor */
NEEDBITS(14);
state->nlen = BITS(5) + 257;
DROPBITS(5);
Tracev((stderr, "inflate: table sizes ok\n"));
state->have = 0;
state->mode = LENLENS;
+
case LENLENS:
+ /* get code length code lengths (not a typo) */
while (state->have < state->ncode) {
NEEDBITS(3);
state->lens[order[state->have++]] = (uint16_t)BITS(3);
Tracev((stderr, "inflate: code lengths ok\n"));
state->have = 0;
state->mode = CODELENS;
+
case CODELENS:
+ /* get length and distance code code lengths */
while (state->have < state->nlen + state->ndist) {
for (;;) {
here = state->lencode[BITS(state->lenbits)];
state->mode = LEN_;
if (flush == Z_TREES)
goto inf_leave;
+
case LEN_:
state->mode = LEN;
+
case LEN:
+ /* use inflate_fast() if we have enough input and output */
if (have >= INFLATE_FAST_MIN_HAVE &&
left >= INFLATE_FAST_MIN_LEFT) {
RESTORE();
break;
}
state->back = 0;
+
+ /* get a literal, length, or end-of-block code */
for (;;) {
here = state->lencode[BITS(state->lenbits)];
if (here.bits <= bits)
DROPBITS(here.bits);
state->back += here.bits;
state->length = here.val;
+
+ /* process literal */
if ((int)(here.op) == 0) {
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
"inflate: literal '%c'\n" :
state->mode = LIT;
break;
}
+
+ /* process end of block */
if (here.op & 32) {
Tracevv((stderr, "inflate: end of block\n"));
state->back = -1;
state->mode = TYPE;
break;
}
+
+ /* invalid code */
if (here.op & 64) {
strm->msg = (char *)"invalid literal/length code";
state->mode = BAD;
break;
}
+
+ /* length code */
state->extra = (here.op & 15);
state->mode = LENEXT;
+
case LENEXT:
+ /* get extra bits, if any */
if (state->extra) {
NEEDBITS(state->extra);
state->length += BITS(state->extra);
Tracevv((stderr, "inflate: length %u\n", state->length));
state->was = state->length;
state->mode = DIST;
+
case DIST:
+ /* get distance code */
for (;;) {
here = state->distcode[BITS(state->distbits)];
if (here.bits <= bits)
state->offset = here.val;
state->extra = (here.op & 15);
state->mode = DISTEXT;
+
case DISTEXT:
+ /* get distance extra bits, if any */
if (state->extra) {
NEEDBITS(state->extra);
state->offset += BITS(state->extra);
#endif
Tracevv((stderr, "inflate: distance %u\n", state->offset));
state->mode = MATCH;
+
case MATCH:
+ /* copy match from window to output */
if (left == 0) goto inf_leave;
copy = out - left;
if (state->offset > copy) { /* copy from window */
if (state->length == 0)
state->mode = LEN;
break;
+
case LIT:
if (left == 0)
goto inf_leave;
left--;
state->mode = LEN;
break;
+
case CHECK:
if (state->wrap) {
NEEDBITS(32);
}
#ifdef GUNZIP
state->mode = LENGTH;
+
case LENGTH:
if (state->wrap && state->flags) {
NEEDBITS(32);
}
#endif
state->mode = DONE;
+
case DONE:
+ /* inflate stream terminated properly */
ret = Z_STREAM_END;
goto inf_leave;
+
case BAD:
ret = Z_DATA_ERROR;
goto inf_leave;
+
case MEM:
return Z_MEM_ERROR;
+
case SYNC:
- default:
+
+ default: /* can't happen, but makes compilers happy */
return Z_STREAM_ERROR;
}