diff options
Diffstat (limited to 'inftrees.c')
-rw-r--r-- | inftrees.c | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -1,12 +1,12 @@ | |||
1 | /* inftrees.c -- generate Huffman trees for efficient decoding | 1 | /* inftrees.c -- generate Huffman trees for efficient decoding |
2 | * Copyright (C) 1995 Mark Adler | 2 | * Copyright (C) 1995-1996 Mark Adler |
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "zutil.h" | 6 | #include "zutil.h" |
7 | #include "inftrees.h" | 7 | #include "inftrees.h" |
8 | 8 | ||
9 | char inflate_copyright[] = " inflate 1.0 Copyright 1995 Mark Adler "; | 9 | char inflate_copyright[] = " inflate 1.0.1 Copyright 1995-1996 Mark Adler "; |
10 | /* | 10 | /* |
11 | If you use the zlib library in a product, an acknowledgment is welcome | 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 | 12 | in the documentation of your product. If for some reason you cannot |
@@ -38,18 +38,18 @@ local voidpf falloc OF(( | |||
38 | uInt)); /* size of item */ | 38 | uInt)); /* size of item */ |
39 | 39 | ||
40 | /* Tables for deflate from PKZIP's appnote.txt. */ | 40 | /* Tables for deflate from PKZIP's appnote.txt. */ |
41 | local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */ | 41 | local 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, | 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}; | 43 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; |
44 | /* actually lengths - 2; also see note #13 above about 258 */ | 44 | /* actually lengths - 2; also see note #13 above about 258 */ |
45 | local uInt cplext[] = { /* Extra bits for literal codes 257..285 */ | 45 | local 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, | 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, 192, 192}; /* 192==invalid */ | 47 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */ |
48 | local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */ | 48 | local uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */ |
49 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, | 49 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
50 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, | 50 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
51 | 8193, 12289, 16385, 24577}; | 51 | 8193, 12289, 16385, 24577}; |
52 | local uInt cpdext[] = { /* Extra bits for distance codes */ | 52 | local uInt cpdext[30] = { /* Extra bits for distance codes */ |
53 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, | 53 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, |
54 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, | 54 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, |
55 | 12, 12, 13, 13}; | 55 | 12, 12, 13, 13}; |
@@ -215,7 +215,8 @@ z_stream *zs; /* for zalloc function */ | |||
215 | w += l; /* previous table always l bits */ | 215 | w += l; /* previous table always l bits */ |
216 | 216 | ||
217 | /* compute minimum size table less than or equal to l bits */ | 217 | /* compute minimum size table less than or equal to l bits */ |
218 | z = (z = g - w) > (uInt)l ? l : z; /* table size upper limit */ | 218 | z = g - w; |
219 | z = z > (uInt)l ? l : z; /* table size upper limit */ | ||
219 | if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ | 220 | if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ |
220 | { /* too few codes for k-w bit table */ | 221 | { /* too few codes for k-w bit table */ |
221 | f -= a + 1; /* deduct codes from patterns left */ | 222 | f -= a + 1; /* deduct codes from patterns left */ |
@@ -268,7 +269,7 @@ z_stream *zs; /* for zalloc function */ | |||
268 | } | 269 | } |
269 | else | 270 | else |
270 | { | 271 | { |
271 | r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */ | 272 | r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */ |
272 | r.base = d[*p++ - s]; | 273 | r.base = d[*p++ - s]; |
273 | } | 274 | } |
274 | 275 | ||
@@ -307,11 +308,11 @@ z_stream *z; /* for zfree function */ | |||
307 | 308 | ||
308 | r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z); | 309 | r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z); |
309 | if (r == Z_DATA_ERROR) | 310 | if (r == Z_DATA_ERROR) |
310 | z->msg = "oversubscribed dynamic bit lengths tree"; | 311 | z->msg = (char*)"oversubscribed dynamic bit lengths tree"; |
311 | else if (r == Z_BUF_ERROR) | 312 | else if (r == Z_BUF_ERROR) |
312 | { | 313 | { |
313 | inflate_trees_free(*tb, z); | 314 | inflate_trees_free(*tb, z); |
314 | z->msg = "incomplete dynamic bit lengths tree"; | 315 | z->msg = (char*)"incomplete dynamic bit lengths tree"; |
315 | r = Z_DATA_ERROR; | 316 | r = Z_DATA_ERROR; |
316 | } | 317 | } |
317 | return r; | 318 | return r; |
@@ -334,11 +335,11 @@ z_stream *z; /* for zfree function */ | |||
334 | if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK) | 335 | if ((r = huft_build(c, nl, 257, cplens, cplext, tl, bl, z)) != Z_OK) |
335 | { | 336 | { |
336 | if (r == Z_DATA_ERROR) | 337 | if (r == Z_DATA_ERROR) |
337 | z->msg = "oversubscribed literal/length tree"; | 338 | z->msg = (char*)"oversubscribed literal/length tree"; |
338 | else if (r == Z_BUF_ERROR) | 339 | else if (r == Z_BUF_ERROR) |
339 | { | 340 | { |
340 | inflate_trees_free(*tl, z); | 341 | inflate_trees_free(*tl, z); |
341 | z->msg = "incomplete literal/length tree"; | 342 | z->msg = (char*)"incomplete literal/length tree"; |
342 | r = Z_DATA_ERROR; | 343 | r = Z_DATA_ERROR; |
343 | } | 344 | } |
344 | return r; | 345 | return r; |
@@ -348,14 +349,14 @@ z_stream *z; /* for zfree function */ | |||
348 | if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK) | 349 | if ((r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, z)) != Z_OK) |
349 | { | 350 | { |
350 | if (r == Z_DATA_ERROR) | 351 | if (r == Z_DATA_ERROR) |
351 | z->msg = "oversubscribed literal/length tree"; | 352 | z->msg = (char*)"oversubscribed literal/length tree"; |
352 | else if (r == Z_BUF_ERROR) { | 353 | else if (r == Z_BUF_ERROR) { |
353 | #ifdef PKZIP_BUG_WORKAROUND | 354 | #ifdef PKZIP_BUG_WORKAROUND |
354 | r = Z_OK; | 355 | r = Z_OK; |
355 | } | 356 | } |
356 | #else | 357 | #else |
357 | inflate_trees_free(*td, z); | 358 | inflate_trees_free(*td, z); |
358 | z->msg = "incomplete literal/length tree"; | 359 | z->msg = (char*)"incomplete literal/length tree"; |
359 | r = Z_DATA_ERROR; | 360 | r = Z_DATA_ERROR; |
360 | } | 361 | } |
361 | inflate_trees_free(*tl, z); | 362 | inflate_trees_free(*tl, z); |
@@ -385,7 +386,7 @@ uInt s; /* size of item */ | |||
385 | { | 386 | { |
386 | Assert(s == sizeof(inflate_huft) && n <= *(intf *)q, | 387 | Assert(s == sizeof(inflate_huft) && n <= *(intf *)q, |
387 | "inflate_trees falloc overflow"); | 388 | "inflate_trees falloc overflow"); |
388 | *(intf *)q -= n; | 389 | *(intf *)q -= n+s-s; /* s-s to avoid warning */ |
389 | return (voidpf)(fixed_mem + *(intf *)q); | 390 | return (voidpf)(fixed_mem + *(intf *)q); |
390 | } | 391 | } |
391 | 392 | ||