diff options
Diffstat (limited to 'cpan/Compress-Raw-Zlib/zlib-src/inflate.c')
-rw-r--r-- | cpan/Compress-Raw-Zlib/zlib-src/inflate.c | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/cpan/Compress-Raw-Zlib/zlib-src/inflate.c b/cpan/Compress-Raw-Zlib/zlib-src/inflate.c index ca45202cf5..72dc4c1f33 100644 --- a/cpan/Compress-Raw-Zlib/zlib-src/inflate.c +++ b/cpan/Compress-Raw-Zlib/zlib-src/inflate.c @@ -1,5 +1,5 @@ /* inflate.c -- zlib decompression - * Copyright (C) 1995-2011 Mark Adler + * Copyright (C) 1995-2010 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -100,7 +100,7 @@ local int updatewindow OF((z_streamp strm, unsigned out)); local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, unsigned len)); -int ZEXPORT inflateResetKeep( +int ZEXPORT inflateReset( z_streamp strm) { struct inflate_state FAR *state; @@ -109,13 +109,15 @@ int ZEXPORT inflateResetKeep( state = (struct inflate_state FAR *)strm->state; strm->total_in = strm->total_out = state->total = 0; strm->msg = Z_NULL; - if (state->wrap) /* to support ill-conceived Java test suite */ - strm->adler = state->wrap & 1; + strm->adler = 1; /* to support ill-conceived Java test suite */ state->mode = HEAD; state->last = 0; state->havedict = 0; state->dmax = 32768U; state->head = Z_NULL; + state->wsize = 0; + state->whave = 0; + state->wnext = 0; state->hold = 0; state->bits = 0; state->lencode = state->distcode = state->next = state->codes; @@ -125,19 +127,6 @@ int ZEXPORT inflateResetKeep( return Z_OK; } -int ZEXPORT inflateReset( - z_streamp strm) -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->wsize = 0; - state->whave = 0; - state->wnext = 0; - return inflateResetKeep(strm); -} - int ZEXPORT inflateReset2( z_streamp strm, int windowBits) @@ -191,19 +180,10 @@ int ZEXPORT inflateInit2_( if (strm == Z_NULL) return Z_STREAM_ERROR; strm->msg = Z_NULL; /* in case we return an error */ if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else strm->zalloc = zcalloc; strm->opaque = (voidpf)0; -#endif } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif + 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; @@ -341,8 +321,8 @@ void makefixed() low = 0; for (;;) { 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); + printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, + state.lencode[low].val); if (++low == size) break; putchar(','); } @@ -945,6 +925,7 @@ int ZEXPORT inflate( PULLBYTE(); } if (here.val < 16) { + NEEDBITS(here.bits); DROPBITS(here.bits); state->lens[state->have++] = here.val; } @@ -1233,8 +1214,7 @@ int ZEXPORT inflate( */ inf_leave: RESTORE(); - if (state->wsize || (out != strm->avail_out && state->mode < BAD && - (state->mode < CHECK || flush != Z_FINISH))) + if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) if (updatewindow(strm, out)) { state->mode = MEM; return Z_MEM_ERROR; @@ -1276,9 +1256,6 @@ int ZEXPORT inflateSetDictionary( { struct inflate_state FAR *state; unsigned long id; - unsigned char *next; - unsigned avail; - int ret; /* check state */ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; @@ -1294,19 +1271,21 @@ int ZEXPORT inflateSetDictionary( return Z_DATA_ERROR; } - /* copy dictionary to window using updatewindow(), which will amend the - existing dictionary if appropriate */ - next = strm->next_out; - avail = strm->avail_out; - strm->next_out = (Bytef *)dictionary + dictLength; - strm->avail_out = 0; - ret = updatewindow(strm, dictLength); - strm->avail_out = avail; - strm->next_out = next; - if (ret) { + /* copy dictionary to window */ + if (updatewindow(strm, strm->avail_out)) { state->mode = MEM; return Z_MEM_ERROR; } + if (dictLength > state->wsize) { + zmemcpy(state->window, dictionary + dictLength - state->wsize, + state->wsize); + 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; @@ -1454,8 +1433,8 @@ int ZEXPORT inflateCopy( } /* copy state */ - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); + zmemcpy(dest, source, sizeof(z_stream)); + zmemcpy(copy, state, sizeof(struct inflate_state)); if (state->lencode >= state->codes && state->lencode <= state->codes + ENOUGH - 1) { copy->lencode = copy->codes + (state->lencode - state->codes); |