diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-11-06 15:02:02 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-11-27 14:15:40 -0800 |
commit | 383d2cdab7662d21a3c720139635fe0fbc451a71 (patch) | |
tree | 23a9a814dca02204a1e7493a91e301000d6d7d4a /inftrees.c | |
parent | 1b57de3aef88bd0a7b80c11db3631281b08b650a (diff) | |
download | zlib-383d2cdab7662d21a3c720139635fe0fbc451a71.tar.gz zlib-383d2cdab7662d21a3c720139635fe0fbc451a71.tar.bz2 zlib-383d2cdab7662d21a3c720139635fe0fbc451a71.zip |
Simplify incomplete code table filling in inflate_table().
Due to earlier changes in the error checking in inflate_table(), the
code to fill in a table for an incomplete code handled cases that can
never actually occur. This simplifies that code to handle the only
possible case, which is a single empty table entry for a code with
a single symbol with a length of one bit.
Diffstat (limited to 'inftrees.c')
-rw-r--r-- | inftrees.c | 40 |
1 files changed, 8 insertions, 32 deletions
@@ -289,38 +289,14 @@ unsigned short FAR *work; | |||
289 | } | 289 | } |
290 | } | 290 | } |
291 | 291 | ||
292 | /* | 292 | /* fill in remaining table entry if code is incomplete (guaranteed to have |
293 | Fill in rest of table for incomplete codes. This loop is similar to the | 293 | at most one remaining entry, since if the code is incomplete, the |
294 | loop above in incrementing huff for table indices. It is assumed that | 294 | maximum code length that was allowed to get this far is one bit) */ |
295 | len is equal to curr + drop, so there is no loop needed to increment | 295 | if (huff != 0) { |
296 | through high index bits. When the current sub-table is filled, the loop | 296 | here.op = (unsigned char)64; /* invalid code marker */ |
297 | drops back to the root table to fill in any remaining entries there. | 297 | here.bits = (unsigned char)(len - drop); |
298 | */ | 298 | here.val = (unsigned short)0; |
299 | here.op = (unsigned char)64; /* invalid code marker */ | 299 | next[huff] = here; |
300 | here.bits = (unsigned char)(len - drop); | ||
301 | here.val = (unsigned short)0; | ||
302 | while (huff != 0) { | ||
303 | /* when done with sub-table, drop back to root table */ | ||
304 | if (drop != 0 && (huff & mask) != low) { | ||
305 | drop = 0; | ||
306 | len = root; | ||
307 | next = *table; | ||
308 | here.bits = (unsigned char)len; | ||
309 | } | ||
310 | |||
311 | /* put invalid code marker in table */ | ||
312 | next[huff >> drop] = here; | ||
313 | |||
314 | /* backwards increment the len-bit code huff */ | ||
315 | incr = 1U << (len - 1); | ||
316 | while (huff & incr) | ||
317 | incr >>= 1; | ||
318 | if (incr != 0) { | ||
319 | huff &= incr - 1; | ||
320 | huff += incr; | ||
321 | } | ||
322 | else | ||
323 | huff = 0; | ||
324 | } | 300 | } |
325 | 301 | ||
326 | /* set return parameters */ | 302 | /* set return parameters */ |