summaryrefslogtreecommitdiff
path: root/inftrees.c
diff options
context:
space:
mode:
Diffstat (limited to 'inftrees.c')
-rw-r--r--inftrees.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/inftrees.c b/inftrees.c
index fb8d843..2b12d70 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -1,5 +1,5 @@
1/* inftrees.c -- generate Huffman trees for efficient decoding 1/* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2006 Mark Adler 2 * Copyright (C) 1995-2009 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
@@ -9,7 +9,7 @@
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate_copyright[] = 11const char inflate_copyright[] =
12 " inflate 1.2.3.3 Copyright 1995-2006 Mark Adler "; 12 " inflate 1.2.3.4 Copyright 1995-2008 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot 15 in the documentation of your product. If for some reason you cannot
@@ -62,7 +62,7 @@ unsigned short FAR *work;
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 203}; 65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 200};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
@@ -123,7 +123,7 @@ unsigned short FAR *work;
123 *bits = 1; 123 *bits = 1;
124 return 0; /* no symbols, but wait for decoding to report error */ 124 return 0; /* no symbols, but wait for decoding to report error */
125 } 125 }
126 for (min = 1; min <= MAXBITS; min++) 126 for (min = 1; min < max; min++)
127 if (count[min] != 0) break; 127 if (count[min] != 0) break;
128 if (root < min) root = min; 128 if (root < min) root = min;
129 129
@@ -166,11 +166,10 @@ unsigned short FAR *work;
166 entered in the tables. 166 entered in the tables.
167 167
168 used keeps track of how many table entries have been allocated from the 168 used keeps track of how many table entries have been allocated from the
169 provided *table space. It is checked when a LENS table is being made 169 provided *table space. It is checked for LENS and DIST tables against
170 against the space in *table, ENOUGH, minus the maximum space needed by 170 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
171 the worst case distance code, MAXD. This should never happen, but the 171 the initial root table size constants. See the comments in inftrees.h
172 sufficiency of ENOUGH has not been proven exhaustively, hence the check. 172 for more information.
173 This assumes that when type == LENS, bits == 9.
174 173
175 sym increments through all symbols, and the loop terminates when 174 sym increments through all symbols, and the loop terminates when
176 all codes of length max, i.e. all codes, have been processed. This 175 all codes of length max, i.e. all codes, have been processed. This
@@ -209,7 +208,8 @@ unsigned short FAR *work;
209 mask = used - 1; /* mask for comparing low */ 208 mask = used - 1; /* mask for comparing low */
210 209
211 /* check available table space */ 210 /* check available table space */
212 if (type == LENS && used >= ENOUGH - MAXD) 211 if ((type == LENS && used >= ENOUGH_LENS) ||
212 (type == DISTS && used >= ENOUGH_DISTS))
213 return 1; 213 return 1;
214 214
215 /* process all codes and make table entries */ 215 /* process all codes and make table entries */
@@ -277,7 +277,8 @@ unsigned short FAR *work;
277 277
278 /* check for enough space */ 278 /* check for enough space */
279 used += 1U << curr; 279 used += 1U << curr;
280 if (type == LENS && used >= ENOUGH - MAXD) 280 if ((type == LENS && used >= ENOUGH_LENS) ||
281 (type == DISTS && used >= ENOUGH_DISTS))
281 return 1; 282 return 1;
282 283
283 /* point entry in root table to sub-table */ 284 /* point entry in root table to sub-table */