X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fdecompress.c;h=6ca0f1616c767bb4b4b8fcb7abf343478b4b4c7a;hp=5c308b2d7bd2cdfba9425fc41c8cdf7abed11219;hb=caa6d1f3c73c22a5a6425c215fce20eacec940e1;hpb=1530b6dab02a9e1e5faf81529ab502aee68d8cd2 diff --git a/src/decompress.c b/src/decompress.c index 5c308b2d..6ca0f161 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2012 Eric Biggers + * Copyright (C) 2012, 2013 Eric Biggers * * This file is part of wimlib, a library for working with WIM files. * @@ -89,9 +89,10 @@ * indices into the decoding table, and symbol entries are distinguished from * pointers by the fact that values less than @num_syms must be symbol values. */ -int make_huffman_decode_table(u16 decode_table[], unsigned num_syms, - unsigned table_bits, const u8 lens[], - unsigned max_codeword_len) +int +make_huffman_decode_table(u16 decode_table[], unsigned num_syms, + unsigned table_bits, const u8 lens[], + unsigned max_codeword_len) { unsigned len_counts[max_codeword_len + 1]; u16 sorted_syms[num_syms]; @@ -167,6 +168,10 @@ int make_huffman_decode_table(u16 decode_table[], unsigned num_syms, const unsigned entries_per_long = sizeof(unsigned long) / sizeof(decode_table[0]); if (num_entries >= entries_per_long) { + /* Fill in the Huffman decode table entries one unsigned + * long at a time. On 32-bit systems this is 2 entries + * per store, while on 64-bit systems this is 4 entries + * per store. */ wimlib_assert2(decode_table_pos % entries_per_long == 0); BUILD_BUG_ON(sizeof(unsigned long) != 4 && sizeof(unsigned long) != 8); @@ -176,14 +181,21 @@ int make_huffman_decode_table(u16 decode_table[], unsigned num_syms, unsigned long v = sym; if (sizeof(unsigned long) >= 4) v |= v << 16; - if (sizeof(unsigned long) >= 8) + if (sizeof(unsigned long) >= 8) { + /* This may produce a compiler warning if an + * unsigned long is 32 bits, but this won't be + * executed unless an unsigned long is at least + * 64 bits anyway. */ v |= v << 32; + } do { *p++ = v; } while (--n); decode_table_pos += num_entries; } else { + /* Fill in the Huffman decode table entries one 16-bit + * integer at a time. */ do { decode_table[decode_table_pos++] = sym; } while (--num_entries); @@ -234,7 +246,6 @@ int make_huffman_decode_table(u16 decode_table[], unsigned num_syms, unsigned sym = sorted_syms[i]; unsigned codeword_len = lens[sym]; unsigned extra_bits = codeword_len - table_bits; - unsigned extra_mask; cur_codeword <<= (codeword_len - prev_codeword_len); prev_codeword_len = codeword_len; @@ -284,12 +295,13 @@ int make_huffman_decode_table(u16 decode_table[], unsigned num_syms, /* Reads a Huffman-encoded symbol from the bistream when the number of remaining * bits is less than the maximum codeword length. */ -int read_huffsym_near_end_of_input(struct input_bitstream *istream, - const u16 decode_table[], - const u8 lens[], - unsigned num_syms, - unsigned table_bits, - unsigned *n) +int +read_huffsym_near_end_of_input(struct input_bitstream *istream, + const u16 decode_table[], + const u8 lens[], + unsigned num_syms, + unsigned table_bits, + unsigned *n) { unsigned bitsleft = istream->bitsleft; unsigned key_size;