X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Flzx-compress.c;h=49aff104f9101da6801776875e47ab68c8b5aec8;hb=f55116f8cdb1581ec14b91a231292d464194bac3;hp=a811d51c9ec9ffd43a5064d853b89aca888b1cc8;hpb=92d96f9e2db42196a778b727cfa91d18a5cc6f49;p=wimlib diff --git a/src/lzx-compress.c b/src/lzx-compress.c index a811d51c..49aff104 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -57,9 +57,16 @@ * blocks from one input chunk is not yet implemented. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "wimlib.h" -#include "lzx.h" -#include "compress.h" +#include "wimlib/compress.h" +#include "wimlib/error.h" +#include "wimlib/lzx.h" +#include "wimlib/util.h" + #include #include @@ -567,7 +574,7 @@ lzx_write_compressed_tree(struct output_bitstream *out, /* Builds the canonical Huffman code for the main tree, the length tree, and the * aligned offset tree. */ -static void +static void lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs, struct lzx_codes *codes) { @@ -591,10 +598,10 @@ lzx_make_huffman_codes(const struct lzx_freq_tables *freq_tabs, static void do_call_insn_translation(u32 *call_insn_target, int input_pos, - int32_t file_size) + s32 file_size) { - int32_t abs_offset; - int32_t rel_offset; + s32 abs_offset; + s32 rel_offset; rel_offset = le32_to_cpu(*call_insn_target); if (rel_offset >= -input_pos && rel_offset < file_size) { @@ -669,6 +676,7 @@ wimlib_lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len, /* The input data must be preprocessed. To avoid changing the original * input, copy it to a temporary buffer. */ memcpy(uncompressed_data, __uncompressed_data, uncompressed_len); + memset(uncompressed_data + uncompressed_len, 0, 8); /* Before doing any actual compression, do the call instruction (0xe8 * byte) translation on the uncompressed data. */ @@ -746,21 +754,23 @@ wimlib_lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len, #ifdef ENABLE_VERIFY_COMPRESSION /* Verify that we really get the same thing back when decompressing. */ - u8 buf[uncompressed_len]; - ret = wimlib_lzx_decompress(compressed_data, compressed_len, - buf, uncompressed_len); - if (ret != 0) { - ERROR("lzx_compress(): Failed to decompress data we compressed"); - abort(); - } - - for (i = 0; i < uncompressed_len; i++) { - if (buf[i] != *((u8*)__uncompressed_data + i)) { - ERROR("lzx_compress(): Data we compressed didn't " - "decompress to the original data (difference at " - "byte %u of %u)", i + 1, uncompressed_len); + { + u8 buf[uncompressed_len]; + ret = wimlib_lzx_decompress(compressed_data, compressed_len, + buf, uncompressed_len); + if (ret != 0) { + ERROR("lzx_compress(): Failed to decompress data we compressed"); abort(); } + + for (i = 0; i < uncompressed_len; i++) { + if (buf[i] != *((u8*)__uncompressed_data + i)) { + ERROR("lzx_compress(): Data we compressed didn't " + "decompress to the original data (difference at " + "byte %u of %u)", i + 1, uncompressed_len); + abort(); + } + } } #endif return compressed_len;