summaryrefslogtreecommitdiff
path: root/infblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'infblock.c')
-rw-r--r--infblock.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/infblock.c b/infblock.c
index 7e9c7af..17943ab 100644
--- a/infblock.c
+++ b/infblock.c
@@ -71,11 +71,7 @@ uLongf *c;
71 if (s->mode == BTREE || s->mode == DTREE) 71 if (s->mode == BTREE || s->mode == DTREE)
72 ZFREE(z, s->sub.trees.blens); 72 ZFREE(z, s->sub.trees.blens);
73 if (s->mode == CODES) 73 if (s->mode == CODES)
74 {
75 inflate_codes_free(s->sub.decode.codes, z); 74 inflate_codes_free(s->sub.decode.codes, z);
76 inflate_trees_free(s->sub.decode.td, z);
77 inflate_trees_free(s->sub.decode.tl, z);
78 }
79 s->mode = TYPE; 75 s->mode = TYPE;
80 s->bitk = 0; 76 s->bitk = 0;
81 s->bitb = 0; 77 s->bitb = 0;
@@ -96,8 +92,15 @@ uInt w;
96 if ((s = (inflate_blocks_statef *)ZALLOC 92 if ((s = (inflate_blocks_statef *)ZALLOC
97 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL) 93 (z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
98 return s; 94 return s;
95 if ((s->hufts =
96 (inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
97 {
98 ZFREE(z, s);
99 return Z_NULL;
100 }
99 if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL) 101 if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
100 { 102 {
103 ZFREE(z, s->hufts);
101 ZFREE(z, s); 104 ZFREE(z, s);
102 return Z_NULL; 105 return Z_NULL;
103 } 106 }
@@ -110,9 +113,6 @@ uInt w;
110} 113}
111 114
112 115
113#ifdef DEBUG
114 extern uInt inflate_hufts;
115#endif
116int inflate_blocks(s, z, r) 116int inflate_blocks(s, z, r)
117inflate_blocks_statef *s; 117inflate_blocks_statef *s;
118z_streamp z; 118z_streamp z;
@@ -153,15 +153,13 @@ int r;
153 uInt bl, bd; 153 uInt bl, bd;
154 inflate_huft *tl, *td; 154 inflate_huft *tl, *td;
155 155
156 inflate_trees_fixed(&bl, &bd, &tl, &td); 156 inflate_trees_fixed(&bl, &bd, &tl, &td, z);
157 s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); 157 s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
158 if (s->sub.decode.codes == Z_NULL) 158 if (s->sub.decode.codes == Z_NULL)
159 { 159 {
160 r = Z_MEM_ERROR; 160 r = Z_MEM_ERROR;
161 LEAVE 161 LEAVE
162 } 162 }
163 s->sub.decode.tl = Z_NULL; /* don't try to free these */
164 s->sub.decode.td = Z_NULL;
165 } 163 }
166 DUMPBITS(3) 164 DUMPBITS(3)
167 s->mode = CODES; 165 s->mode = CODES;
@@ -244,7 +242,7 @@ int r;
244 s->sub.trees.blens[border[s->sub.trees.index++]] = 0; 242 s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
245 s->sub.trees.bb = 7; 243 s->sub.trees.bb = 7;
246 t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, 244 t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
247 &s->sub.trees.tb, z); 245 &s->sub.trees.tb, s->hufts, z);
248 if (t != Z_OK) 246 if (t != Z_OK)
249 { 247 {
250 ZFREE(z, s->sub.trees.blens); 248 ZFREE(z, s->sub.trees.blens);
@@ -286,7 +284,6 @@ int r;
286 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || 284 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
287 (c == 16 && i < 1)) 285 (c == 16 && i < 1))
288 { 286 {
289 inflate_trees_free(s->sub.trees.tb, z);
290 ZFREE(z, s->sub.trees.blens); 287 ZFREE(z, s->sub.trees.blens);
291 s->mode = BAD; 288 s->mode = BAD;
292 z->msg = (char*)"invalid bit length repeat"; 289 z->msg = (char*)"invalid bit length repeat";
@@ -300,7 +297,6 @@ int r;
300 s->sub.trees.index = i; 297 s->sub.trees.index = i;
301 } 298 }
302 } 299 }
303 inflate_trees_free(s->sub.trees.tb, z);
304 s->sub.trees.tb = Z_NULL; 300 s->sub.trees.tb = Z_NULL;
305 { 301 {
306 uInt bl, bd; 302 uInt bl, bd;
@@ -310,11 +306,9 @@ int r;
310 bl = 9; /* must be <= 9 for lookahead assumptions */ 306 bl = 9; /* must be <= 9 for lookahead assumptions */
311 bd = 6; /* must be <= 9 for lookahead assumptions */ 307 bd = 6; /* must be <= 9 for lookahead assumptions */
312 t = s->sub.trees.table; 308 t = s->sub.trees.table;
313#ifdef DEBUG
314 inflate_hufts = 0;
315#endif
316 t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), 309 t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
317 s->sub.trees.blens, &bl, &bd, &tl, &td, z); 310 s->sub.trees.blens, &bl, &bd, &tl, &td,
311 s->hufts, z);
318 ZFREE(z, s->sub.trees.blens); 312 ZFREE(z, s->sub.trees.blens);
319 if (t != Z_OK) 313 if (t != Z_OK)
320 { 314 {
@@ -323,18 +317,13 @@ int r;
323 r = t; 317 r = t;
324 LEAVE 318 LEAVE
325 } 319 }
326 Tracev((stderr, "inflate: trees ok, %d * %d bytes used\n", 320 Tracev((stderr, "inflate: trees ok\n"));
327 inflate_hufts, sizeof(inflate_huft)));
328 if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) 321 if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
329 { 322 {
330 inflate_trees_free(td, z);
331 inflate_trees_free(tl, z);
332 r = Z_MEM_ERROR; 323 r = Z_MEM_ERROR;
333 LEAVE 324 LEAVE
334 } 325 }
335 s->sub.decode.codes = c; 326 s->sub.decode.codes = c;
336 s->sub.decode.tl = tl;
337 s->sub.decode.td = td;
338 } 327 }
339 s->mode = CODES; 328 s->mode = CODES;
340 case CODES: 329 case CODES:
@@ -343,8 +332,6 @@ int r;
343 return inflate_flush(s, z, r); 332 return inflate_flush(s, z, r);
344 r = Z_OK; 333 r = Z_OK;
345 inflate_codes_free(s->sub.decode.codes, z); 334 inflate_codes_free(s->sub.decode.codes, z);
346 inflate_trees_free(s->sub.decode.td, z);
347 inflate_trees_free(s->sub.decode.tl, z);
348 LOAD 335 LOAD
349 Tracev((stderr, "inflate: codes end, %lu total out\n", 336 Tracev((stderr, "inflate: codes end, %lu total out\n",
350 z->total_out + (q >= s->read ? q - s->read : 337 z->total_out + (q >= s->read ? q - s->read :
@@ -386,6 +373,7 @@ z_streamp z;
386{ 373{
387 inflate_blocks_reset(s, z, Z_NULL); 374 inflate_blocks_reset(s, z, Z_NULL);
388 ZFREE(z, s->window); 375 ZFREE(z, s->window);
376 ZFREE(z, s->hufts);
389 ZFREE(z, s); 377 ZFREE(z, s);
390 Tracev((stderr, "inflate: blocks freed\n")); 378 Tracev((stderr, "inflate: blocks freed\n"));
391 return Z_OK; 379 return Z_OK;
@@ -397,7 +385,7 @@ inflate_blocks_statef *s;
397const Bytef *d; 385const Bytef *d;
398uInt n; 386uInt n;
399{ 387{
400 zmemcpy((charf *)s->window, d, n); 388 zmemcpy(s->window, d, n);
401 s->read = s->write = s->window + n; 389 s->read = s->write = s->window + n;
402} 390}
403 391