From b8c9ecb0765fc39423c07613d909c5193378bdfd Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Fri, 9 Sep 2011 23:19:21 -0700 Subject: zlib 1.0.9 --- infblock.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'infblock.c') diff --git a/infblock.c b/infblock.c index 7e9c7af..17943ab 100644 --- a/infblock.c +++ b/infblock.c @@ -71,11 +71,7 @@ uLongf *c; if (s->mode == BTREE || s->mode == DTREE) ZFREE(z, s->sub.trees.blens); if (s->mode == CODES) - { inflate_codes_free(s->sub.decode.codes, z); - inflate_trees_free(s->sub.decode.td, z); - inflate_trees_free(s->sub.decode.tl, z); - } s->mode = TYPE; s->bitk = 0; s->bitb = 0; @@ -96,8 +92,15 @@ uInt w; if ((s = (inflate_blocks_statef *)ZALLOC (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) return s; + if ((s->hufts = + (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL) + { + ZFREE(z, s); + return Z_NULL; + } if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) { + ZFREE(z, s->hufts); ZFREE(z, s); return Z_NULL; } @@ -110,9 +113,6 @@ uInt w; } -#ifdef DEBUG - extern uInt inflate_hufts; -#endif int inflate_blocks(s, z, r) inflate_blocks_statef *s; z_streamp z; @@ -153,15 +153,13 @@ int r; uInt bl, bd; inflate_huft *tl, *td; - inflate_trees_fixed(&bl, &bd, &tl, &td); + inflate_trees_fixed(&bl, &bd, &tl, &td, z); s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); if (s->sub.decode.codes == Z_NULL) { r = Z_MEM_ERROR; LEAVE } - s->sub.decode.tl = Z_NULL; /* don't try to free these */ - s->sub.decode.td = Z_NULL; } DUMPBITS(3) s->mode = CODES; @@ -244,7 +242,7 @@ int r; s->sub.trees.blens[border[s->sub.trees.index++]] = 0; s->sub.trees.bb = 7; t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, - &s->sub.trees.tb, z); + &s->sub.trees.tb, s->hufts, z); if (t != Z_OK) { ZFREE(z, s->sub.trees.blens); @@ -286,7 +284,6 @@ int r; if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) { - inflate_trees_free(s->sub.trees.tb, z); ZFREE(z, s->sub.trees.blens); s->mode = BAD; z->msg = (char*)"invalid bit length repeat"; @@ -300,7 +297,6 @@ int r; s->sub.trees.index = i; } } - inflate_trees_free(s->sub.trees.tb, z); s->sub.trees.tb = Z_NULL; { uInt bl, bd; @@ -310,11 +306,9 @@ int r; bl = 9; /* must be <= 9 for lookahead assumptions */ bd = 6; /* must be <= 9 for lookahead assumptions */ t = s->sub.trees.table; -#ifdef DEBUG - inflate_hufts = 0; -#endif t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), - s->sub.trees.blens, &bl, &bd, &tl, &td, z); + s->sub.trees.blens, &bl, &bd, &tl, &td, + s->hufts, z); ZFREE(z, s->sub.trees.blens); if (t != Z_OK) { @@ -323,18 +317,13 @@ int r; r = t; LEAVE } - Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n", - inflate_hufts, sizeof(inflate_huft))); + Tracev((stderr, "inflate: trees ok\n")); if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) { - inflate_trees_free(td, z); - inflate_trees_free(tl, z); r = Z_MEM_ERROR; LEAVE } s->sub.decode.codes = c; - s->sub.decode.tl = tl; - s->sub.decode.td = td; } s->mode = CODES; case CODES: @@ -343,8 +332,6 @@ int r; return inflate_flush(s, z, r); r = Z_OK; inflate_codes_free(s->sub.decode.codes, z); - inflate_trees_free(s->sub.decode.td, z); - inflate_trees_free(s->sub.decode.tl, z); LOAD Tracev((stderr, "inflate: codes end, %lu total out\n", z->total_out + (q >= s->read ? q - s->read : @@ -386,6 +373,7 @@ z_streamp z; { inflate_blocks_reset(s, z, Z_NULL); ZFREE(z, s->window); + ZFREE(z, s->hufts); ZFREE(z, s); Tracev((stderr, "inflate: blocks freed\n")); return Z_OK; @@ -397,7 +385,7 @@ inflate_blocks_statef *s; const Bytef *d; uInt n; { - zmemcpy((charf *)s->window, d, n); + zmemcpy(s->window, d, n); s->read = s->write = s->window + n; } -- cgit v1.2.3-55-g6feb