#ifdef BUILDFIXED
void makefixed OF((void));
#endif
-local unsigned syncsearch OF((unsigned *have, unsigned char FAR *buf,
+local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
unsigned len));
int ZEXPORT inflateReset(strm)
state->last = 0;
state->havedict = 0;
state->wsize = 0;
+ state->whave = 0;
state->hold = 0;
state->bits = 0;
state->lencode = state->distcode = state->next = state->codes;
return Z_VERSION_ERROR;
if (strm == Z_NULL) return Z_STREAM_ERROR;
strm->msg = Z_NULL; /* in case we return an error */
- if (strm->zalloc == Z_NULL) {
+ if (strm->zalloc == (alloc_func)0) {
strm->zalloc = zcalloc;
strm->opaque = (voidpf)0;
}
- if (strm->zfree == Z_NULL) strm->zfree = zcfree;
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
state = (struct inflate_state FAR *)
ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
else {
state->wrap = (windowBits >> 4) + 1;
#ifdef GUNZIP
- windowBits &= 15;
+ if (windowBits < 48) windowBits &= 15;
#endif
}
if (windowBits < 8 || windowBits > 15) {
if (state->wsize == 0) {
state->wsize = 1U << state->wbits;
state->write = 0;
+ state->whave = 0;
}
/* copy state->wsize or less output bytes into the circular window */
if (copy >= state->wsize) {
zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
state->write = 0;
+ state->whave = state->wsize;
}
else {
dist = state->wsize - state->write;
if (copy) {
zmemcpy(state->window, strm->next_out - copy, copy);
state->write = copy;
+ state->whave = state->wsize;
}
else {
state->write += dist;
if (state->write == state->wsize) state->write = 0;
+ if (state->whave < state->wsize) state->whave += dist;
}
}
return 0;
int flush;
{
struct inflate_state FAR *state;
- unsigned char *next, *put; /* next input and output */
+ unsigned char FAR *next; /* next input */
+ unsigned char FAR *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
- unsigned char *from; /* where to copy match bytes from */
+ unsigned char FAR *from; /* where to copy match bytes from */
code this; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
+ if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
LOAD();
in = have;
out = left;
strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = TYPE;
case TYPE:
+ if (flush == Z_BLOCK) goto inf_leave;
+ case TYPEDO:
if (state->last) {
BYTEBITS();
state->mode = CHECK;
state->offset += BITS(state->extra);
DROPBITS(state->extra);
}
- if (state->offset > (state->wsize ? state->wsize :
- out - left)) {
+ if (state->offset > state->whave + out - left) {
strm->msg = (char *)"invalid distance too far back";
state->mode = BAD;
break;
if (state->wrap && out)
strm->adler = state->check =
UPDATE(state->check, strm->next_out - out, out);
+ strm->data_type = state->bits + (state->last ? 8 : 0) +
+ (state->mode == TYPE ? 16 : 0);
if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
ret = Z_BUF_ERROR;
return ret;
z_streamp strm;
{
struct inflate_state FAR *state;
- if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == Z_NULL)
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (state->window != Z_NULL) ZFREE(strm, state->window);
state->mode = MEM;
return Z_MEM_ERROR;
}
- if (dictLength > state->wsize)
+ if (dictLength > state->wsize) {
zmemcpy(state->window, dictionary + dictLength - state->wsize,
state->wsize);
- else
+ state->whave = state->wsize;
+ }
+ else {
zmemcpy(state->window + state->wsize - dictLength, dictionary,
dictLength);
+ state->whave = dictLength;
+ }
state->havedict = 1;
Tracev((stderr, "inflate: dictionary set\n"));
return Z_OK;
zero for the first call.
*/
local unsigned syncsearch(have, buf, len)
-unsigned *have;
+unsigned FAR *have;
unsigned char FAR *buf;
unsigned len;
{
/* check input */
if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
- source->zalloc == Z_NULL || source->zfree == Z_NULL)
+ source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)source->state;