]> wimlib.net Git - wimlib/blobdiff - src/xpress-compress.c
Win32 apply
[wimlib] / src / xpress-compress.c
index 77df527994483f7062bfadab49f14405456b74cd..1b3951d0a60e92a857659fc686b516d65edb3ec9 100644 (file)
@@ -7,7 +7,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.
  *
@@ -90,7 +90,7 @@ static int xpress_write_compressed_literals(struct output_bitstream *ostream,
 
 static u32 xpress_record_literal(u8 literal, void *__freq_tab)
 {
-       u32 *freq_tab = __freq_tab;
+       freq_t *freq_tab = __freq_tab;
        freq_tab[literal]++;
        return literal;
 }
@@ -121,7 +121,7 @@ static u32 xpress_record_match(unsigned match_offset, unsigned match_len,
        u32 len_hdr = min(adjusted_match_len, 0xf);
        u32 offset_bsr = bsr32(match_offset);
        u32 sym = len_hdr | (offset_bsr << 4) | XPRESS_NUM_CHARS;
-       ((u32*)freq_tab)[sym]++;
+       ((freq_t*)freq_tab)[sym]++;
        return adjusted_match_len | (match_offset << 16);
 }
 
@@ -159,7 +159,7 @@ int xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len,
        u8 *compressed_data = __compressed_data;
        struct output_bitstream ostream;
        u32 match_tab[uncompressed_len];
-       u32 freq_tab[XPRESS_NUM_SYMBOLS];
+       freq_t freq_tab[XPRESS_NUM_SYMBOLS];
        u16 codewords[XPRESS_NUM_SYMBOLS];
        u8 lens[XPRESS_NUM_SYMBOLS];
        unsigned num_matches;
@@ -169,8 +169,14 @@ int xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len,
 
        /* XPRESS requires 256 bytes of overhead for the Huffman tables, so it's
         * impossible cannot compress 256 bytes or less of data to less than the
-        * input size. */
-       if (uncompressed_len <= XPRESS_NUM_SYMBOLS / 2)
+        * input size.
+        *
+        * +1 to take into account that the buffer for compressed data is 1 byte
+        * smaller than the buffer for uncompressed data.
+        *
+        * +4 to take into account that init_output_bitstream() requires at
+        * least 4 bytes of data. */
+       if (uncompressed_len < XPRESS_NUM_SYMBOLS / 2 + 1 + 4)
                return 1;
 
        ZERO_ARRAY(freq_tab);