Deleted Added
full compact
inftrees.c (29747) inftrees.c (33904)
1/* inftrees.c -- generate Huffman trees for efficient decoding
1/* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-1996 Mark Adler
2 * Copyright (C) 1995-1998 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7#include "inftrees.h"
8
9char inflate_copyright[] = " inflate 1.0.4 Copyright 1995-1996 Mark Adler ";
9const char inflate_copyright[] =
10 " inflate 1.1.1 Copyright 1995-1998 Mark Adler ";
10/*
11 If you use the zlib library in a product, an acknowledgment is welcome
12 in the documentation of your product. If for some reason you cannot
13 include such an acknowledgment, I would appreciate that you keep this
14 copyright string in the executable of your product.
15 */
16struct internal_state {int dummy;}; /* for buggy compilers */
17

--- 7 unchanged lines hidden (view full) ---

25local int huft_build OF((
26 uIntf *, /* code lengths in bits */
27 uInt, /* number of codes */
28 uInt, /* number of "simple" codes */
29 const uIntf *, /* list of base values for non-simple codes */
30 const uIntf *, /* list of extra bits for non-simple codes */
31 inflate_huft * FAR*,/* result: starting table */
32 uIntf *, /* maximum lookup bits (returns actual) */
11/*
12 If you use the zlib library in a product, an acknowledgment is welcome
13 in the documentation of your product. If for some reason you cannot
14 include such an acknowledgment, I would appreciate that you keep this
15 copyright string in the executable of your product.
16 */
17struct internal_state {int dummy;}; /* for buggy compilers */
18

--- 7 unchanged lines hidden (view full) ---

26local int huft_build OF((
27 uIntf *, /* code lengths in bits */
28 uInt, /* number of codes */
29 uInt, /* number of "simple" codes */
30 const uIntf *, /* list of base values for non-simple codes */
31 const uIntf *, /* list of extra bits for non-simple codes */
32 inflate_huft * FAR*,/* result: starting table */
33 uIntf *, /* maximum lookup bits (returns actual) */
33 z_streamp )); /* for zalloc function */
34 inflate_huft *, /* space for trees */
35 uInt *, /* hufts used in space */
36 uIntf * )); /* space for values */
34
37
35local voidpf falloc OF((
36 voidpf, /* opaque pointer (not used) */
37 uInt, /* number of items */
38 uInt)); /* size of item */
39
40/* Tables for deflate from PKZIP's appnote.txt. */
41local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
42 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
43 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
44 /* see note #13 above about 258 */
45local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
46 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
47 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */

--- 36 unchanged lines hidden (view full) ---

84 about one bit more than those, so lbits is 8+1 and dbits is 5+1.
85 The optimum values may differ though from machine to machine, and
86 possibly even between compilers. Your mileage may vary.
87 */
88
89
90/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
91#define BMAX 15 /* maximum bit length of any code */
38/* Tables for deflate from PKZIP's appnote.txt. */
39local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
40 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
41 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
42 /* see note #13 above about 258 */
43local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
44 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
45 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */

--- 36 unchanged lines hidden (view full) ---

82 about one bit more than those, so lbits is 8+1 and dbits is 5+1.
83 The optimum values may differ though from machine to machine, and
84 possibly even between compilers. Your mileage may vary.
85 */
86
87
88/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
89#define BMAX 15 /* maximum bit length of any code */
92#define N_MAX 288 /* maximum number of codes in any set */
93
90
94#ifdef DEBUG
95 uInt inflate_hufts;
96#endif
97
98local int huft_build(b, n, s, d, e, t, m, zs)
91local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
99uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
92uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
100uInt n; /* number of codes (assumed <= N_MAX) */
93uInt n; /* number of codes (assumed <= 288) */
101uInt s; /* number of simple-valued codes (0..s-1) */
102const uIntf *d; /* list of base values for non-simple codes */
103const uIntf *e; /* list of extra bits for non-simple codes */
104inflate_huft * FAR *t; /* result: starting table */
105uIntf *m; /* maximum lookup bits, returns actual */
94uInt s; /* number of simple-valued codes (0..s-1) */
95const uIntf *d; /* list of base values for non-simple codes */
96const uIntf *e; /* list of extra bits for non-simple codes */
97inflate_huft * FAR *t; /* result: starting table */
98uIntf *m; /* maximum lookup bits, returns actual */
106z_streamp zs; /* for zalloc function */
99inflate_huft *hp; /* space for trees */
100uInt *hn; /* hufts used in space */
101uIntf *v; /* working area: values in order of bit length */
107/* Given a list of code lengths and a maximum table size, make a set of
108 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
109 if the given code set is incomplete (the tables are still built in this
110 case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
111 lengths), or Z_MEM_ERROR if not enough memory. */
112{
113
114 uInt a; /* counter for codes of length k */
115 uInt c[BMAX+1]; /* bit length count table */
116 uInt f; /* i repeats in table every f entries */
117 int g; /* maximum code length */
118 int h; /* table level */
119 register uInt i; /* counter, current code */
120 register uInt j; /* counter */
121 register int k; /* number of bits in current code */
122 int l; /* bits per table (returned in m) */
102/* Given a list of code lengths and a maximum table size, make a set of
103 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
104 if the given code set is incomplete (the tables are still built in this
105 case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
106 lengths), or Z_MEM_ERROR if not enough memory. */
107{
108
109 uInt a; /* counter for codes of length k */
110 uInt c[BMAX+1]; /* bit length count table */
111 uInt f; /* i repeats in table every f entries */
112 int g; /* maximum code length */
113 int h; /* table level */
114 register uInt i; /* counter, current code */
115 register uInt j; /* counter */
116 register int k; /* number of bits in current code */
117 int l; /* bits per table (returned in m) */
118 uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
123 register uIntf *p; /* pointer into c[], b[], or v[] */
124 inflate_huft *q; /* points to current table */
125 struct inflate_huft_s r; /* table entry for structure assignment */
126 inflate_huft *u[BMAX]; /* table stack */
119 register uIntf *p; /* pointer into c[], b[], or v[] */
120 inflate_huft *q; /* points to current table */
121 struct inflate_huft_s r; /* table entry for structure assignment */
122 inflate_huft *u[BMAX]; /* table stack */
127 uInt v[N_MAX]; /* values in order of bit length */
128 register int w; /* bits before this table == (l * h) */
129 uInt x[BMAX+1]; /* bit offsets, then code stack */
130 uIntf *xp; /* pointer into x */
131 int y; /* number of dummy codes added */
132 uInt z; /* number of entries in current table */
133
134
135 /* Generate counts for each bit length */

--- 49 unchanged lines hidden (view full) ---

185
186
187 /* Make a table of values in order of bit lengths */
188 p = b; i = 0;
189 do {
190 if ((j = *p++) != 0)
191 v[x[j]++] = i;
192 } while (++i < n);
123 register int w; /* bits before this table == (l * h) */
124 uInt x[BMAX+1]; /* bit offsets, then code stack */
125 uIntf *xp; /* pointer into x */
126 int y; /* number of dummy codes added */
127 uInt z; /* number of entries in current table */
128
129
130 /* Generate counts for each bit length */

--- 49 unchanged lines hidden (view full) ---

180
181
182 /* Make a table of values in order of bit lengths */
183 p = b; i = 0;
184 do {
185 if ((j = *p++) != 0)
186 v[x[j]++] = i;
187 } while (++i < n);
193 n = x[g]; /* set n to length of v */
188 n = x[g]; /* set n to length of v */
194
195
196 /* Generate the Huffman codes and for each, make the table entries */
197 x[0] = i = 0; /* first Huffman code is zero */
198 p = v; /* grab values in bit order */
199 h = -1; /* no tables yet--level -1 */
200 w = -l; /* bits decoded == (l * h) */
201 u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */

--- 25 unchanged lines hidden (view full) ---

227 {
228 if ((f <<= 1) <= *++xp)
229 break; /* enough codes to use up j bits */
230 f -= *xp; /* else deduct codes from patterns */
231 }
232 }
233 z = 1 << j; /* table entries for j-bit table */
234
189
190
191 /* Generate the Huffman codes and for each, make the table entries */
192 x[0] = i = 0; /* first Huffman code is zero */
193 p = v; /* grab values in bit order */
194 h = -1; /* no tables yet--level -1 */
195 w = -l; /* bits decoded == (l * h) */
196 u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */

--- 25 unchanged lines hidden (view full) ---

222 {
223 if ((f <<= 1) <= *++xp)
224 break; /* enough codes to use up j bits */
225 f -= *xp; /* else deduct codes from patterns */
226 }
227 }
228 z = 1 << j; /* table entries for j-bit table */
229
235 /* allocate and link in new table */
236 if ((q = (inflate_huft *)ZALLOC
237 (zs,z + 1,sizeof(inflate_huft))) == Z_NULL)
238 {
239 if (h)
240 inflate_trees_free(u[0], zs);
230 /* allocate new table */
231 if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
241 return Z_MEM_ERROR; /* not enough memory */
232 return Z_MEM_ERROR; /* not enough memory */
233 u[h] = q = hp + *hn;
234 *hn += z;
235 if (t != Z_NULL) /* first table is returned result */
236 {
237 *t = q;
238 t = Z_NULL;
242 }
239 }
243#ifdef DEBUG
244 inflate_hufts += z + 1;
245#endif
246 *t = q + 1; /* link to list for huft_free() */
247 *(t = &(q->next)) = Z_NULL;
248 u[h] = ++q; /* table starts after link */
249
250 /* connect to last table, if there is one */
251 if (h)
252 {
253 x[h] = i; /* save pattern for backing up */
254 r.bits = (Byte)l; /* bits to dump before this table */
255 r.exop = (Byte)j; /* bits in this table */
256 r.next = q; /* pointer to this table */

--- 23 unchanged lines hidden (view full) ---

280 q[j] = r;
281
282 /* backwards increment the k-bit code i */
283 for (j = 1 << (k - 1); i & j; j >>= 1)
284 i ^= j;
285 i ^= j;
286
287 /* backup over finished tables */
240
241 /* connect to last table, if there is one */
242 if (h)
243 {
244 x[h] = i; /* save pattern for backing up */
245 r.bits = (Byte)l; /* bits to dump before this table */
246 r.exop = (Byte)j; /* bits in this table */
247 r.next = q; /* pointer to this table */

--- 23 unchanged lines hidden (view full) ---

271 q[j] = r;
272
273 /* backwards increment the k-bit code i */
274 for (j = 1 << (k - 1); i & j; j >>= 1)
275 i ^= j;
276 i ^= j;
277
278 /* backup over finished tables */
288 while ((i & ((1 << w) - 1)) != x[h])
279 mask = (1 << w) - 1; /* needed on HP, cc -O bug */
280 while ((i & mask) != x[h])
289 {
290 h--; /* don't need to update q */
291 w -= l;
281 {
282 h--; /* don't need to update q */
283 w -= l;
284 mask = (1 << w) - 1;
292 }
293 }
294 }
295
296
297 /* Return Z_BUF_ERROR if we were given an incomplete table */
298 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
299}
300
301
285 }
286 }
287 }
288
289
290 /* Return Z_BUF_ERROR if we were given an incomplete table */
291 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
292}
293
294
302int inflate_trees_bits(c, bb, tb, z)
295int inflate_trees_bits(c, bb, tb, hp, z)
303uIntf *c; /* 19 code lengths */
304uIntf *bb; /* bits tree desired/actual depth */
305inflate_huft * FAR *tb; /* bits tree result */
296uIntf *c; /* 19 code lengths */
297uIntf *bb; /* bits tree desired/actual depth */
298inflate_huft * FAR *tb; /* bits tree result */
306z_streamp z; /* for zfree function */
299inflate_huft *hp; /* space for trees */
300z_streamp z; /* for messages */
307{
308 int r;
301{
302 int r;
303 uInt hn = 0; /* hufts used in space */
304 uIntf *v; /* work area for huft_build */
309
305
310 r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z);
306 if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
307 return Z_MEM_ERROR;
308 r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
309 tb, bb, hp, &hn, v);
311 if (r == Z_DATA_ERROR)
312 z->msg = (char*)"oversubscribed dynamic bit lengths tree";
313 else if (r == Z_BUF_ERROR || *bb == 0)
314 {
310 if (r == Z_DATA_ERROR)
311 z->msg = (char*)"oversubscribed dynamic bit lengths tree";
312 else if (r == Z_BUF_ERROR || *bb == 0)
313 {
315 inflate_trees_free(*tb, z);
316 z->msg = (char*)"incomplete dynamic bit lengths tree";
317 r = Z_DATA_ERROR;
318 }
314 z->msg = (char*)"incomplete dynamic bit lengths tree";
315 r = Z_DATA_ERROR;
316 }
317 ZFREE(z, v);
319 return r;
320}
321
322
318 return r;
319}
320
321
323int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z)
322int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
324uInt nl; /* number of literal/length codes */
325uInt nd; /* number of distance codes */
326uIntf *c; /* that many (total) code lengths */
327uIntf *bl; /* literal desired/actual bit depth */
328uIntf *bd; /* distance desired/actual bit depth */
329inflate_huft * FAR *tl; /* literal/length tree result */
330inflate_huft * FAR *td; /* distance tree result */
323uInt nl; /* number of literal/length codes */
324uInt nd; /* number of distance codes */
325uIntf *c; /* that many (total) code lengths */
326uIntf *bl; /* literal desired/actual bit depth */
327uIntf *bd; /* distance desired/actual bit depth */
328inflate_huft * FAR *tl; /* literal/length tree result */
329inflate_huft * FAR *td; /* distance tree result */
331z_streamp z; /* for zfree function */
330inflate_huft *hp; /* space for trees */
331z_streamp z; /* for messages */
332{
333 int r;
332{
333 int r;
334 uInt hn = 0; /* hufts used in space */
335 uIntf *v; /* work area for huft_build */
334
336
337 /* allocate work area */
338 if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
339 return Z_MEM_ERROR;
340
335 /* build literal/length tree */
341 /* build literal/length tree */
336 r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z);
342 r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
337 if (r != Z_OK || *bl == 0)
338 {
339 if (r == Z_DATA_ERROR)
340 z->msg = (char*)"oversubscribed literal/length tree";
341 else if (r != Z_MEM_ERROR)
342 {
343 if (r != Z_OK || *bl == 0)
344 {
345 if (r == Z_DATA_ERROR)
346 z->msg = (char*)"oversubscribed literal/length tree";
347 else if (r != Z_MEM_ERROR)
348 {
343 inflate_trees_free(*tl, z);
344 z->msg = (char*)"incomplete literal/length tree";
345 r = Z_DATA_ERROR;
346 }
349 z->msg = (char*)"incomplete literal/length tree";
350 r = Z_DATA_ERROR;
351 }
352 ZFREE(z, v);
347 return r;
348 }
349
350 /* build distance tree */
353 return r;
354 }
355
356 /* build distance tree */
351 r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z);
357 r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
352 if (r != Z_OK || (*bd == 0 && nl > 257))
353 {
354 if (r == Z_DATA_ERROR)
355 z->msg = (char*)"oversubscribed distance tree";
356 else if (r == Z_BUF_ERROR) {
357#ifdef PKZIP_BUG_WORKAROUND
358 r = Z_OK;
359 }
360#else
358 if (r != Z_OK || (*bd == 0 && nl > 257))
359 {
360 if (r == Z_DATA_ERROR)
361 z->msg = (char*)"oversubscribed distance tree";
362 else if (r == Z_BUF_ERROR) {
363#ifdef PKZIP_BUG_WORKAROUND
364 r = Z_OK;
365 }
366#else
361 inflate_trees_free(*td, z);
362 z->msg = (char*)"incomplete distance tree";
363 r = Z_DATA_ERROR;
364 }
365 else if (r != Z_MEM_ERROR)
366 {
367 z->msg = (char*)"empty distance tree with lengths";
368 r = Z_DATA_ERROR;
369 }
367 z->msg = (char*)"incomplete distance tree";
368 r = Z_DATA_ERROR;
369 }
370 else if (r != Z_MEM_ERROR)
371 {
372 z->msg = (char*)"empty distance tree with lengths";
373 r = Z_DATA_ERROR;
374 }
370 inflate_trees_free(*tl, z);
375 ZFREE(z, v);
371 return r;
372#endif
373 }
374
375 /* done */
376 return r;
377#endif
378 }
379
380 /* done */
381 ZFREE(z, v);
376 return Z_OK;
377}
378
379
380/* build fixed tables only once--keep them here */
381local int fixed_built = 0;
382 return Z_OK;
383}
384
385
386/* build fixed tables only once--keep them here */
387local int fixed_built = 0;
382#define FIXEDH 530 /* number of hufts used by fixed tables */
388#define FIXEDH 424 /* number of hufts used by fixed tables */
383local inflate_huft fixed_mem[FIXEDH];
384local uInt fixed_bl;
385local uInt fixed_bd;
386local inflate_huft *fixed_tl;
387local inflate_huft *fixed_td;
388
389
389local inflate_huft fixed_mem[FIXEDH];
390local uInt fixed_bl;
391local uInt fixed_bd;
392local inflate_huft *fixed_tl;
393local inflate_huft *fixed_td;
394
395
390local voidpf falloc(q, n, s)
391voidpf q; /* opaque pointer */
392uInt n; /* number of items */
393uInt s; /* size of item */
394{
395 Assert(s == sizeof(inflate_huft) && n <= *(intf *)q,
396 "inflate_trees falloc overflow");
397 *(intf *)q -= n+s-s; /* s-s to avoid warning */
398 return (voidpf)(fixed_mem + *(intf *)q);
399}
400
401
402int inflate_trees_fixed(bl, bd, tl, td)
396int inflate_trees_fixed(bl, bd, tl, td, z)
403uIntf *bl; /* literal desired/actual bit depth */
404uIntf *bd; /* distance desired/actual bit depth */
405inflate_huft * FAR *tl; /* literal/length tree result */
406inflate_huft * FAR *td; /* distance tree result */
397uIntf *bl; /* literal desired/actual bit depth */
398uIntf *bd; /* distance desired/actual bit depth */
399inflate_huft * FAR *tl; /* literal/length tree result */
400inflate_huft * FAR *td; /* distance tree result */
401z_streamp z; /* for memory allocation */
407{
408 /* build fixed tables if not already (multiple overlapped executions ok) */
409 if (!fixed_built)
410 {
411 int k; /* temporary variable */
402{
403 /* build fixed tables if not already (multiple overlapped executions ok) */
404 if (!fixed_built)
405 {
406 int k; /* temporary variable */
412 unsigned c[288]; /* length list for huft_build */
413 z_stream z; /* for falloc function */
414 int f = FIXEDH; /* number of hufts left in fixed_mem */
407 uInt f = 0; /* number of hufts used in fixed_mem */
408 uIntf *c; /* length list for huft_build */
409 uIntf *v; /* work area for huft_build */
415
410
416 /* set up fake z_stream for memory routines */
417 z.zalloc = falloc;
418 z.zfree = Z_NULL;
419 z.opaque = (voidpf)&f;
411 /* allocate memory */
412 if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
413 return Z_MEM_ERROR;
414 if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
415 {
416 ZFREE(z, c);
417 return Z_MEM_ERROR;
418 }
420
421 /* literal table */
422 for (k = 0; k < 144; k++)
423 c[k] = 8;
424 for (; k < 256; k++)
425 c[k] = 9;
426 for (; k < 280; k++)
427 c[k] = 7;
428 for (; k < 288; k++)
429 c[k] = 8;
430 fixed_bl = 7;
419
420 /* literal table */
421 for (k = 0; k < 144; k++)
422 c[k] = 8;
423 for (; k < 256; k++)
424 c[k] = 9;
425 for (; k < 280; k++)
426 c[k] = 7;
427 for (; k < 288; k++)
428 c[k] = 8;
429 fixed_bl = 7;
431 huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl, &z);
430 huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
431 fixed_mem, &f, v);
432
433 /* distance table */
434 for (k = 0; k < 30; k++)
435 c[k] = 5;
436 fixed_bd = 5;
432
433 /* distance table */
434 for (k = 0; k < 30; k++)
435 c[k] = 5;
436 fixed_bd = 5;
437 huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd, &z);
437 huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
438 fixed_mem, &f, v);
438
439 /* done */
439
440 /* done */
440 Assert(f == 0, "invalid build of fixed tables");
441 ZFREE(z, v);
442 ZFREE(z, c);
441 fixed_built = 1;
442 }
443 *bl = fixed_bl;
444 *bd = fixed_bd;
445 *tl = fixed_tl;
446 *td = fixed_td;
447 return Z_OK;
448}
443 fixed_built = 1;
444 }
445 *bl = fixed_bl;
446 *bd = fixed_bd;
447 *tl = fixed_tl;
448 *td = fixed_td;
449 return Z_OK;
450}
449
450
451int inflate_trees_free(t, z)
452inflate_huft *t; /* table to free */
453z_streamp z; /* for zfree function */
454/* Free the malloc'ed tables built by huft_build(), which makes a linked
455 list of the tables it made, with the links in a dummy first entry of
456 each table. */
457{
458 register inflate_huft *p, *q, *r;
459
460 /* Reverse linked list */
461 p = Z_NULL;
462 q = t;
463 while (q != Z_NULL)
464 {
465 r = (q - 1)->next;
466 (q - 1)->next = p;
467 p = q;
468 q = r;
469 }
470 /* Go through linked list, freeing from the malloced (t[-1]) address. */
471 while (p != Z_NULL)
472 {
473 q = (--p)->next;
474 ZFREE(z,p);
475 p = q;
476 }
477 return Z_OK;
478}