X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Flzx-compress.c;h=b23c2df088642ce2d9001ebeba130d8fbba504d8;hp=c829a4272d5b2011ba619e5dc06f30c6e93908e0;hb=2a94ebd67e2a341208c4849a92442ecd511fb716;hpb=720db87557918105b17b51b03f264ddb9b89d2b9 diff --git a/src/lzx-compress.c b/src/lzx-compress.c index c829a427..b23c2df0 100644 --- a/src/lzx-compress.c +++ b/src/lzx-compress.c @@ -27,8 +27,8 @@ /* - * This file provides lzx_compress(), a function to compress an in-memory buffer - * of data using LZX compression, as used in the WIM file format. + * This file provides wimlib_lzx_compress(), a function to compress an in-memory + * buffer of data using LZX compression, as used in the WIM file format. * * Please see the comments in lzx-decompress.c for more information about this * compression format. @@ -57,6 +57,7 @@ * blocks from one input chunk is not yet implemented. */ +#include "wimlib.h" #include "lzx.h" #include "compress.h" #include @@ -566,7 +567,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) { @@ -638,15 +639,10 @@ static const struct lz_params lzx_lz_params = { .too_far = 4096, }; -/* - * Performs LZX compression on a block of data. - * - * Please see the documentation for the 'compress_func_t' type in write.c for - * the exact behavior of this function and how to call it. - */ -unsigned -lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len, - void *compressed_data) +/* Documented in wimlib.h */ +WIMLIBAPI unsigned +wimlib_lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len, + void *compressed_data) { struct output_bitstream ostream; u8 uncompressed_data[uncompressed_len + 8]; @@ -673,6 +669,7 @@ 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. */ @@ -750,21 +747,23 @@ 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 = 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;