#include "inffast.h"
/* function prototypes */
-local void fixedtables (struct inflate_state *state);
+local void fixedtables(struct inflate_state *state);
/*
strm provides memory allocation functions in zalloc and zfree, or
window and output buffer that is 2**windowBits bytes.
*/
int ZEXPORT inflateBackInit_(z_stream *strm, int windowBits, unsigned char *window,
- const char *version, int stream_size)
-{
+ const char *version, int stream_size) {
struct inflate_state *state;
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
- stream_size != (int)(sizeof(z_stream)))
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
- if (strm == Z_NULL || window == Z_NULL ||
- windowBits < 8 || windowBits > 15)
+ if (strm == Z_NULL || window == Z_NULL || windowBits < 8 || windowBits > 15)
return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
strm->opaque = NULL;
}
if (strm->zfree == (free_func)0)
- strm->zfree = zcfree;
- state = (struct inflate_state *)ZALLOC(strm, 1,
- sizeof(struct inflate_state));
- if (state == Z_NULL) return Z_MEM_ERROR;
+ strm->zfree = zcfree;
+ state = (struct inflate_state *)ZALLOC(strm, 1, sizeof(struct inflate_state));
+ if (state == Z_NULL)
+ return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state *)state;
state->dmax = 32768U;
used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe.
*/
-local void fixedtables(struct inflate_state *state)
-{
+local void fixedtables(struct inflate_state *state) {
#ifdef BUILDFIXED
static int virgin = 1;
static code *lenfix, *distfix;
inflateBack() can also return Z_STREAM_ERROR if the input parameters
are not correct, i.e. strm is Z_NULL or the state was not initialized.
*/
-int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc,
- out_func out, void *out_desc)
-{
+int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, out_func out, void *out_desc) {
struct inflate_state *state;
const unsigned char *next; /* next input */
unsigned char *put; /* next output */
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: stored block%s\n", state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: fixed codes block%s\n", state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */
break;
case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: dynamic codes block%s\n", state->last ? " (last)" : ""));
state->mode = TABLE;
break;
case 3:
break;
}
state->length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
- state->length));
+ Tracev((stderr, "inflate: stored length %u\n", state->length));
INITBITS();
/* copy stored block from input to output */
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;
state->next = state->codes;
state->lencode = (code const *)(state->next);
state->lenbits = 7;
- ret = inflate_table(CODES, state->lens, 19, &(state->next),
- &(state->lenbits), state->work);
+ ret = inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
state->mode = BAD;
while (state->have < state->nlen + state->ndist) {
for (;;) {
here = state->lencode[BITS(state->lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
+ if ((unsigned)(here.bits) <= bits)
+ break;
PULLBYTE();
}
if (here.val < 16) {
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
- }
- else {
+ } else {
if (here.val == 16) {
NEEDBITS(here.bits + 2);
DROPBITS(here.bits);
len = (unsigned)(state->lens[state->have - 1]);
copy = 3 + BITS(2);
DROPBITS(2);
- }
- else if (here.val == 17) {
+ } else if (here.val == 17) {
NEEDBITS(here.bits + 3);
DROPBITS(here.bits);
len = 0;
copy = 3 + BITS(3);
DROPBITS(3);
- }
- else {
+ } else {
NEEDBITS(here.bits + 7);
DROPBITS(here.bits);
len = 0;
}
/* handle error breaks in while */
- if (state->mode == BAD) break;
+ if (state->mode == BAD)
+ break;
/* check for end-of-block code (better have one) */
if (state->lens[256] == 0) {
state->next = state->codes;
state->lencode = (code const *)(state->next);
state->lenbits = 9;
- ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
- &(state->lenbits), state->work);
+ ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
state->mode = BAD;
state->distcode = (code const *)(state->next);
state->distbits = 6;
ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
- &(state->next), &(state->distbits), state->work);
+ &(state->next), &(state->distbits), state->work);
if (ret) {
strm->msg = (char *)"invalid distances set";
state->mode = BAD;
/* get a literal, length, or end-of-block code */
for (;;) {
here = state->lencode[BITS(state->lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
+ if ((unsigned)(here.bits) <= bits)
+ break;
PULLBYTE();
}
if (here.op && (here.op & 0xf0) == 0) {
for (;;) {
here = state->lencode[last.val +
(BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
+ if ((unsigned)(last.bits + here.bits) <= bits)
+ break;
PULLBYTE();
}
DROPBITS(last.bits);
/* get distance code */
for (;;) {
here = state->distcode[BITS(state->distbits)];
- if ((unsigned)(here.bits) <= bits) break;
+ if ((unsigned)(here.bits) <= bits)
+ break;
PULLBYTE();
}
if ((here.op & 0xf0) == 0) {
last = here;
for (;;) {
- here = state->distcode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
+ here = state->distcode[last.val + (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + here.bits) <= bits)
+ break;
PULLBYTE();
}
DROPBITS(last.bits);
state->offset += BITS(state->extra);
DROPBITS(state->extra);
}
- if (state->offset > state->wsize - (state->whave < state->wsize ?
- left : 0)) {
+ if (state->offset > state->wsize - (state->whave < state->wsize ? left : 0)) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
if (copy < left) {
from = put + copy;
copy = left - copy;
- }
- else {
+ } else {
from = put - state->offset;
copy = left;
}
- if (copy > state->length) copy = state->length;
+ if (copy > state->length)
+ copy = state->length;
state->length -= copy;
left -= copy;
do {
return ret;
}
-int ZEXPORT inflateBackEnd(z_stream *strm)
-{
+int ZEXPORT inflateBackEnd(z_stream *strm) {
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
ZFREE(strm, strm->state);
#endif
/* function prototypes */
-local void fixedtables (struct inflate_state *state);
-local int updatewindow (z_stream *strm, const unsigned char *end, unsigned copy);
+local void fixedtables(struct inflate_state *state);
+local int updatewindow(z_stream *strm, const unsigned char *end, unsigned copy);
#ifdef BUILDFIXED
- void makefixed (void);
+ void makefixed(void);
#endif
-local unsigned syncsearch (unsigned *have, const unsigned char *buf, unsigned len);
+local unsigned syncsearch(unsigned *have, const unsigned char *buf, unsigned len);
-int ZEXPORT inflateResetKeep(z_stream *strm)
-{
+int ZEXPORT inflateResetKeep(z_stream *strm) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
strm->total_in = strm->total_out = state->total = 0;
strm->msg = Z_NULL;
return Z_OK;
}
-int ZEXPORT inflateReset(z_stream *strm)
-{
+int ZEXPORT inflateReset(z_stream *strm) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
state->wsize = 0;
state->whave = 0;
return inflateResetKeep(strm);
}
-int ZEXPORT inflateReset2(z_stream *strm, int windowBits)
-{
+int ZEXPORT inflateReset2(z_stream *strm, int windowBits) {
int wrap;
struct inflate_state *state;
/* get the state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
/* extract wrap request from windowBits parameter */
if (windowBits < 0) {
wrap = 0;
windowBits = -windowBits;
- }
- else {
+ } else {
wrap = (windowBits >> 4) + 1;
#ifdef GUNZIP
if (windowBits < 48)
return inflateReset(strm);
}
-int ZEXPORT inflateInit2_(z_stream *strm, int windowBits, const char *version,
- int stream_size)
-{
+int ZEXPORT inflateInit2_(z_stream *strm, int windowBits, const char *version, int stream_size) {
int ret;
struct inflate_state *state;
- if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
- stream_size != (int)(sizeof(z_stream)))
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || stream_size != (int)(sizeof(z_stream)))
return Z_VERSION_ERROR;
- if (strm == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL)
+ return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
if (strm->zalloc == (alloc_func)0) {
strm->zalloc = zcalloc;
}
if (strm->zfree == (free_func)0)
strm->zfree = zcfree;
- state = (struct inflate_state *)
- ZALLOC(strm, 1, sizeof(struct inflate_state));
- if (state == Z_NULL) return Z_MEM_ERROR;
+ state = (struct inflate_state *) ZALLOC(strm, 1, sizeof(struct inflate_state));
+ if (state == Z_NULL)
+ return Z_MEM_ERROR;
Tracev((stderr, "inflate: allocated\n"));
strm->state = (struct internal_state *)state;
state->window = Z_NULL;
return ret;
}
-int ZEXPORT inflateInit_(z_stream *strm, const char *version, int stream_size)
-{
+int ZEXPORT inflateInit_(z_stream *strm, const char *version, int stream_size) {
return inflateInit2_(strm, DEF_WBITS, version, stream_size);
}
-int ZEXPORT inflatePrime(z_stream *strm, int bits, int value)
-{
+int ZEXPORT inflatePrime(z_stream *strm, int bits, int value) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
if (bits < 0) {
state->hold = 0;
state->bits = 0;
return Z_OK;
}
- if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
+ if (bits > 16 || state->bits + bits > 32)
+ return Z_STREAM_ERROR;
value &= (1L << bits) - 1;
state->hold += value << state->bits;
state->bits += bits;
used for threaded applications, since the rewriting of the tables and virgin
may not be thread-safe.
*/
-local void fixedtables(struct inflate_state *state)
-{
+local void fixedtables(struct inflate_state *state) {
#ifdef BUILDFIXED
static int virgin = 1;
static code *lenfix, *distfix;
a.out > inffixed.h
*/
-void makefixed()
-{
+void makefixed(void) {
unsigned low, size;
struct inflate_state state;
printf(" static const code lenfix[%u] = {", size);
low = 0;
for (;;) {
- if ((low % 7) == 0) printf("\n ");
+ if ((low % 7) == 0)
+ printf("\n ");
printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
- state.lencode[low].bits, state.lencode[low].val);
- if (++low == size) break;
+ state.lencode[low].bits, state.lencode[low].val);
+ if (++low == size)
+ break;
putchar(',');
}
puts("\n };");
printf("\n static const code distfix[%u] = {", size);
low = 0;
for (;;) {
- if ((low % 6) == 0) printf("\n ");
- printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
- state.distcode[low].val);
- if (++low == size) break;
+ if ((low % 6) == 0)
+ printf("\n ");
+ printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, state.distcode[low].val);
+ if (++low == size)
+ break;
putchar(',');
}
puts("\n };");
output will fall in the output data, making match copies simpler and faster.
The advantage may be dependent on the size of the processor's data caches.
*/
-local int updatewindow(z_stream *strm, const unsigned char *end, unsigned copy)
-{
+local int updatewindow(z_stream *strm, const unsigned char *end, unsigned copy) {
struct inflate_state *state;
unsigned dist;
/* if it hasn't been done already, allocate space for the window */
if (state->window == Z_NULL) {
- state->window = (unsigned char *)
- ZALLOC(strm, 1U << state->wbits,
- sizeof(unsigned char));
- if (state->window == Z_NULL) return 1;
+ state->window = (unsigned char *) ZALLOC(strm, 1U << state->wbits, sizeof(unsigned char));
+ if (state->window == Z_NULL)
+ return 1;
}
/* if window not in use yet, initialize */
memcpy(state->window, end - state->wsize, state->wsize);
state->wnext = 0;
state->whave = state->wsize;
- }
- else {
+ } else {
dist = state->wsize - state->wnext;
- if (dist > copy) dist = copy;
+ if (dist > copy)
+ dist = copy;
memcpy(state->window + state->wnext, end - copy, dist);
copy -= dist;
if (copy) {
memcpy(state->window, end - copy, copy);
state->wnext = copy;
state->whave = state->wsize;
- }
- else {
+ } else {
state->wnext += dist;
- if (state->wnext == state->wsize) state->wnext = 0;
- if (state->whave < state->wsize) state->whave += dist;
+ if (state->wnext == state->wsize)
+ state->wnext = 0;
+ if (state->whave < state->wsize)
+ state->whave += dist;
}
}
return 0;
will return Z_BUF_ERROR if it has not reached the end of the stream.
*/
-int ZEXPORT inflate(z_stream *strm, int flush)
-{
+int ZEXPORT inflate(z_stream *strm, int flush) {
struct inflate_state *state;
const unsigned char *next; /* next input */
unsigned char *put; /* next output */
return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
- if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
+ if (state->mode == TYPE) /* skip check */
+ state->mode = TYPEDO;
LOAD();
in = have;
out = left;
}
DROPBITS(4);
len = BITS(4) + 8;
- if (state->wbits == 0)
+ if (state->wbits == 0) {
state->wbits = len;
- else if (len > state->wbits) {
+ } else if (len > state->wbits) {
strm->msg = (char *)"invalid window size";
state->mode = BAD;
break;
}
if (state->head != Z_NULL)
state->head->text = (int)((hold >> 8) & 1);
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if (state->flags & 0x0200)
+ CRC2(state->check, hold);
INITBITS();
state->mode = TIME;
case TIME:
NEEDBITS(32);
if (state->head != Z_NULL)
state->head->time = hold;
- if (state->flags & 0x0200) CRC4(state->check, hold);
+ if (state->flags & 0x0200)
+ CRC4(state->check, hold);
INITBITS();
state->mode = OS;
case OS:
state->head->xflags = (int)(hold & 0xff);
state->head->os = (int)(hold >> 8);
}
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if (state->flags & 0x0200)
+ CRC2(state->check, hold);
INITBITS();
state->mode = EXLEN;
case EXLEN:
state->length = (unsigned)(hold);
if (state->head != Z_NULL)
state->head->extra_len = (unsigned)hold;
- if (state->flags & 0x0200) CRC2(state->check, hold);
+ if (state->flags & 0x0200)
+ CRC2(state->check, hold);
INITBITS();
- }
- else if (state->head != Z_NULL)
+ } else if (state->head != Z_NULL) {
state->head->extra = Z_NULL;
+ }
state->mode = EXTRA;
case EXTRA:
if (state->flags & 0x0400) {
copy = state->length;
- if (copy > have) copy = have;
+ if (copy > have)
+ copy = have;
if (copy) {
if (state->head != Z_NULL &&
state->head->extra != Z_NULL) {
next += copy;
state->length -= copy;
}
- if (state->length) goto inf_leave;
+ if (state->length)
+ goto inf_leave;
}
state->length = 0;
state->mode = NAME;
copy = 0;
do {
len = (unsigned)(next[copy++]);
- if (state->head != Z_NULL &&
- state->head->name != Z_NULL &&
- state->length < state->head->name_max)
+ if (state->head != Z_NULL && state->head->name != Z_NULL && state->length < state->head->name_max)
state->head->name[state->length++] = len;
} while (len && copy < have);
if (state->flags & 0x0200)
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
- if (len) goto inf_leave;
- }
- else if (state->head != Z_NULL)
+ if (len)
+ goto inf_leave;
+ } else if (state->head != Z_NULL) {
state->head->name = Z_NULL;
+ }
state->length = 0;
state->mode = COMMENT;
case COMMENT:
copy = 0;
do {
len = (unsigned)(next[copy++]);
- if (state->head != Z_NULL &&
- state->head->comment != Z_NULL &&
- state->length < state->head->comm_max)
+ if (state->head != Z_NULL && state->head->comment != Z_NULL
+ && state->length < state->head->comm_max)
state->head->comment[state->length++] = len;
} while (len && copy < have);
if (state->flags & 0x0200)
state->check = crc32(state->check, next, copy);
have -= copy;
next += copy;
- if (len) goto inf_leave;
- }
- else if (state->head != Z_NULL)
+ if (len)
+ goto inf_leave;
+ } else if (state->head != Z_NULL) {
state->head->comment = Z_NULL;
+ }
state->mode = HCRC;
case HCRC:
if (state->flags & 0x0200) {
strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = TYPE;
case TYPE:
- if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
+ if (flush == Z_BLOCK || flush == Z_TREES)
+ goto inf_leave;
case TYPEDO:
if (state->last) {
BYTEBITS();
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: stored block%s\n", state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: fixed codes block%s\n", state->last ? " (last)" : ""));
state->mode = LEN_; /* decode codes */
if (flush == Z_TREES) {
DROPBITS(2);
}
break;
case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
- state->last ? " (last)" : ""));
+ Tracev((stderr, "inflate: dynamic codes block%s\n", state->last ? " (last)" : ""));
state->mode = TABLE;
break;
case 3:
break;
}
state->length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
- state->length));
+ Tracev((stderr, "inflate: stored length %u\n", state->length));
INITBITS();
state->mode = COPY_;
- if (flush == Z_TREES) goto inf_leave;
+ if (flush == Z_TREES)
+ goto inf_leave;
case COPY_:
state->mode = COPY;
case COPY:
state->next = state->codes;
state->lencode = (const code *)(state->next);
state->lenbits = 7;
- ret = inflate_table(CODES, state->lens, 19, &(state->next),
- &(state->lenbits), state->work);
+ ret = inflate_table(CODES, state->lens, 19, &(state->next), &(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid code lengths set";
state->mode = BAD;
if (here.val < 16) {
DROPBITS(here.bits);
state->lens[state->have++] = here.val;
- }
- else {
+ } else {
if (here.val == 16) {
NEEDBITS(here.bits + 2);
DROPBITS(here.bits);
len = state->lens[state->have - 1];
copy = 3 + BITS(2);
DROPBITS(2);
- }
- else if (here.val == 17) {
+ } else if (here.val == 17) {
NEEDBITS(here.bits + 3);
DROPBITS(here.bits);
len = 0;
copy = 3 + BITS(3);
DROPBITS(3);
- }
- else {
+ } else {
NEEDBITS(here.bits + 7);
DROPBITS(here.bits);
len = 0;
}
/* handle error breaks in while */
- if (state->mode == BAD) break;
+ if (state->mode == BAD)
+ break;
/* check for end-of-block code (better have one) */
if (state->lens[256] == 0) {
state->next = state->codes;
state->lencode = (const code *)(state->next);
state->lenbits = 9;
- ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
- &(state->lenbits), state->work);
+ ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), &(state->lenbits), state->work);
if (ret) {
strm->msg = (char *)"invalid literal/lengths set";
state->mode = BAD;
}
Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN_;
- if (flush == Z_TREES) goto inf_leave;
+ if (flush == Z_TREES)
+ goto inf_leave;
case LEN_:
state->mode = LEN;
case LEN:
state->back = 0;
for (;;) {
here = state->lencode[BITS(state->lenbits)];
- if ((unsigned)(here.bits) <= bits) break;
+ if ((unsigned)(here.bits) <= bits)
+ break;
PULLBYTE();
}
if (here.op && (here.op & 0xf0) == 0) {
last = here;
for (;;) {
- here = state->lencode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
+ here = state->lencode[last.val + (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + here.bits) <= bits)
+ break;
PULLBYTE();
}
DROPBITS(last.bits);
case DIST:
for (;;) {
here = state->distcode[BITS(state->distbits)];
- if ((unsigned)(here.bits) <= bits) break;
+ if ((unsigned)(here.bits) <= bits)
+ break;
PULLBYTE();
}
if ((here.op & 0xf0) == 0) {
last = here;
for (;;) {
- here = state->distcode[last.val +
- (BITS(last.bits + last.op) >> last.bits)];
- if ((unsigned)(last.bits + here.bits) <= bits) break;
+ here = state->distcode[last.val + (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + here.bits) <= bits)
+ break;
PULLBYTE();
}
DROPBITS(last.bits);
#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;
+ if (copy > state->length)
+ copy = state->length;
+ if (copy > left)
+ copy = left;
left -= copy;
state->length -= copy;
do {
*put++ = 0;
} while (--copy);
- if (state->length == 0) state->mode = LEN;
+ if (state->length == 0)
+ state->mode = LEN;
break;
#endif
}
if (copy > state->wnext) {
copy -= state->wnext;
from = state->window + (state->wsize - copy);
- }
- else
+ } else {
from = state->window + (state->wnext - copy);
- if (copy > state->length) copy = state->length;
- }
- else { /* copy from output */
+ }
+ if (copy > state->length)
+ copy = state->length;
+ } else { /* copy from output */
from = put - state->offset;
copy = state->length;
}
- if (copy > left) copy = left;
+ if (copy > left)
+ copy = left;
left -= copy;
state->length -= copy;
do {
*put++ = *from++;
} while (--copy);
- if (state->length == 0) state->mode = LEN;
+ if (state->length == 0)
+ state->mode = LEN;
break;
case LIT:
- if (left == 0) goto inf_leave;
+ if (left == 0)
+ goto inf_leave;
*put++ = (unsigned char)(state->length);
left--;
state->mode = LEN;
strm->total_out += out;
state->total += out;
if (out)
- strm->adler = state->check =
- UPDATE(state->check, put - out, out);
+ strm->adler = state->check = UPDATE(state->check, put - out, out);
out = left;
if ((
#ifdef GUNZIP
*/
inf_leave:
RESTORE();
- if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
- (state->mode < CHECK || flush != Z_FINISH)))
+ if (state->wsize || (out != strm->avail_out && state->mode < BAD && (state->mode < CHECK || flush != Z_FINISH))) {
if (updatewindow(strm, strm->next_out, out - strm->avail_out)) {
state->mode = MEM;
return Z_MEM_ERROR;
}
+ }
in -= strm->avail_in;
out -= strm->avail_out;
strm->total_in += in;
strm->total_out += out;
state->total += out;
if (state->wrap && out)
- strm->adler = state->check =
- UPDATE(state->check, strm->next_out - out, out);
+ strm->adler = state->check = UPDATE(state->check, strm->next_out - out, out);
strm->data_type = state->bits + (state->last ? 64 : 0) +
- (state->mode == TYPE ? 128 : 0) +
- (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
+ (state->mode == TYPE ? 128 : 0) + (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
ret = Z_BUF_ERROR;
return ret;
}
-int ZEXPORT inflateEnd(z_stream *strm)
-{
+int ZEXPORT inflateEnd(z_stream *strm) {
struct inflate_state *state;
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
- if (state->window != Z_NULL) ZFREE(strm, state->window);
+ if (state->window != Z_NULL)
+ ZFREE(strm, state->window);
ZFREE(strm, strm->state);
strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}
-int ZEXPORT inflateGetDictionary(z_stream *strm, unsigned char *dictionary, uInt *dictLength)
-{
+int ZEXPORT inflateGetDictionary(z_stream *strm, unsigned char *dictionary, uInt *dictLength) {
struct inflate_state *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
/* copy dictionary */
if (state->whave && dictionary != Z_NULL) {
- memcpy(dictionary, state->window + state->wnext,
- state->whave - state->wnext);
- memcpy(dictionary + state->whave - state->wnext,
- state->window, state->wnext);
+ memcpy(dictionary, state->window + state->wnext, state->whave - state->wnext);
+ memcpy(dictionary + state->whave - state->wnext, state->window, state->wnext);
}
if (dictLength != Z_NULL)
*dictLength = state->whave;
return Z_OK;
}
-int ZEXPORT inflateSetDictionary(z_stream *strm, const unsigned char *dictionary, uInt dictLength)
-{
+int ZEXPORT inflateSetDictionary(z_stream *strm, const unsigned char *dictionary, uInt dictLength) {
struct inflate_state *state;
uint32_t dictid;
int ret;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
return Z_OK;
}
-int ZEXPORT inflateGetHeader(z_stream *strm, gz_headerp head)
-{
+int ZEXPORT inflateGetHeader(z_stream *strm, gz_headerp head) {
struct inflate_state *state;
/* check state */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
- if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
+ if ((state->wrap & 2) == 0)
+ return Z_STREAM_ERROR;
/* save header structure */
state->head = head;
called again with more data and the *have state. *have is initialized to
zero for the first call.
*/
-local unsigned syncsearch(unsigned *have, const unsigned char *buf, unsigned len)
-{
+local unsigned syncsearch(unsigned *have, const unsigned char *buf, unsigned len) {
unsigned got;
unsigned next;
return next;
}
-int ZEXPORT inflateSync(z_stream *strm)
-{
+int ZEXPORT inflateSync(z_stream *strm) {
unsigned len; /* number of bytes to look at or looked at */
size_t in, out; /* temporary to save total_in and total_out */
unsigned char buf[4]; /* to restore bit buffer to byte string */
struct inflate_state *state;
/* check parameters */
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
- if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
+ if (strm->avail_in == 0 && state->bits < 8)
+ return Z_BUF_ERROR;
/* if first time, start search in bit buffer */
if (state->mode != SYNC) {
strm->total_in += len;
/* return no joy or set up to restart inflate() on a new block */
- if (state->have != 4) return Z_DATA_ERROR;
- in = strm->total_in; out = strm->total_out;
+ if (state->have != 4)
+ return Z_DATA_ERROR;
+ in = strm->total_in;
+ out = strm->total_out;
inflateReset(strm);
- strm->total_in = in; strm->total_out = out;
+ strm->total_in = in;
+ strm->total_out = out;
state->mode = TYPE;
return Z_OK;
}
block. When decompressing, PPP checks that at the end of input packet,
inflate is waiting for these length bytes.
*/
-int ZEXPORT inflateSyncPoint(z_stream *strm)
-{
+int ZEXPORT inflateSyncPoint(z_stream *strm) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
return state->mode == STORED && state->bits == 0;
}
-int ZEXPORT inflateCopy(z_stream *dest, z_stream *source)
-{
+int ZEXPORT inflateCopy(z_stream *dest, z_stream *source) {
struct inflate_state *state;
struct inflate_state *copy;
unsigned char *window;
/* allocate space */
copy = (struct inflate_state *)
ZALLOC(source, 1, sizeof(struct inflate_state));
- if (copy == Z_NULL) return Z_MEM_ERROR;
+ if (copy == Z_NULL)
+ return Z_MEM_ERROR;
window = Z_NULL;
if (state->window != Z_NULL) {
- window = (unsigned char *)
- ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
+ window = (unsigned char *) ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
if (window == Z_NULL) {
ZFREE(source, copy);
return Z_MEM_ERROR;
/* copy state */
memcpy((void *)dest, (void *)source, sizeof(z_stream));
memcpy((void *)copy, (void *)state, sizeof(struct inflate_state));
- if (state->lencode >= state->codes &&
- state->lencode <= state->codes + ENOUGH - 1) {
+ if (state->lencode >= state->codes && state->lencode <= state->codes + ENOUGH - 1) {
copy->lencode = copy->codes + (state->lencode - state->codes);
copy->distcode = copy->codes + (state->distcode - state->codes);
}
return Z_OK;
}
-int ZEXPORT inflateUndermine(z_stream *strm, int subvert)
-{
+int ZEXPORT inflateUndermine(z_stream *strm, int subvert) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state *)strm->state;
state->sane = !subvert;
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
#endif
}
-long ZEXPORT inflateMark(z_stream *strm)
-{
+long ZEXPORT inflateMark(z_stream *strm) {
struct inflate_state *state;
- if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return -1L << 16;
state = (struct inflate_state *)strm->state;
- return ((long)(state->back) << 16) +
- (state->mode == COPY ? state->length :
+ return ((long)(state->back) << 16) + (state->mode == COPY ? state->length :
(state->mode == MATCH ? state->was - state->length : 0));
}