summaryrefslogtreecommitdiff
path: root/inflate.c
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2019-04-10 13:41:58 +0200
committerHans Kristian Rosbach <hk-github@circlestorm.org>2019-05-23 12:44:59 +0200
commitb7f659f2faa899a73f3456c29554769261c1721f (patch)
tree0dfc06602051eff0f809ac8a9eceeb24a9b105d5 /inflate.c
parentf8f08e9e384e9ba7ca495f4383f0fd4676c52c99 (diff)
Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL
Diffstat (limited to 'inflate.c')
-rw-r--r--inflate.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/inflate.c b/inflate.c
index 6ba7627..002dca8 100644
--- a/inflate.c
+++ b/inflate.c
@@ -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) {