diff options
author | Ilya Leoshkevich <iii@linux.ibm.com> | 2019-04-10 13:41:58 +0200 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2019-05-23 12:44:59 +0200 |
commit | b7f659f2faa899a73f3456c29554769261c1721f (patch) | |
tree | 0dfc06602051eff0f809ac8a9eceeb24a9b105d5 /inflate.c | |
parent | f8f08e9e384e9ba7ca495f4383f0fd4676c52c99 (diff) |
Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL
Diffstat (limited to 'inflate.c')
-rw-r--r-- | inflate.c | 49 |
1 files changed, 28 insertions, 21 deletions
@@ -359,6 +359,33 @@ void makefixed(void) { } #endif /* MAKEFIXED */ +int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state) +{ + /* if it hasn't been done already, allocate space for the window */ + if (state->window == NULL) { +#ifdef INFFAST_CHUNKSIZE + unsigned wsize = 1U << state->wbits; + state->window = (unsigned char *) ZALLOC(state->strm, wsize + INFFAST_CHUNKSIZE, sizeof(unsigned char)); + if (state->window == Z_NULL) + return 1; + memset(state->window + wsize, 0, INFFAST_CHUNKSIZE); +#else + state->window = (unsigned char *) ZALLOC(state->strm, 1U << state->wbits, sizeof(unsigned char)); + if (state->window == NULL) + return 1; +#endif + } + + /* if window not in use yet, initialize */ + if (state->wsize == 0) { + state->wsize = 1U << state->wbits; + state->wnext = 0; + state->whave = 0; + } + + return 0; +} + /* Update the window with the last wsize (normally 32K) bytes written before returning. If window does not exist yet, create it. This is only called @@ -379,27 +406,7 @@ static int updatewindow(PREFIX3(stream) *strm, const unsigned char *end, uint32_ state = (struct inflate_state *)strm->state; - /* if it hasn't been done already, allocate space for the window */ - if (state->window == NULL) { -#ifdef INFFAST_CHUNKSIZE - unsigned wsize = 1U << state->wbits; - state->window = (unsigned char *) ZALLOC(strm, wsize + INFFAST_CHUNKSIZE, sizeof(unsigned char)); - if (state->window == Z_NULL) - return 1; - memset(state->window + wsize, 0, INFFAST_CHUNKSIZE); -#else - state->window = (unsigned char *) ZALLOC(strm, 1U << state->wbits, sizeof(unsigned char)); - if (state->window == NULL) - return 1; -#endif - } - - /* if window not in use yet, initialize */ - if (state->wsize == 0) { - state->wsize = 1U << state->wbits; - state->wnext = 0; - state->whave = 0; - } + if (inflate_ensure_window(state)) return 1; /* copy state->wsize or less output bytes into the circular window */ if (copy >= state->wsize) { |