X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fxpress-decompress.c;h=6756b159465d13e72ce5b071ce3531df7c74ef20;hb=34a91e36924e10b924117d91acd116ade58df0b4;hp=eb6b69268825ee6ef09f8d6e5d3a926eaf57bdb1;hpb=10a87017a0a82d34ed3981e1f5e586b5b8613e3f;p=wimlib diff --git a/src/xpress-decompress.c b/src/xpress-decompress.c index eb6b6926..6756b159 100644 --- a/src/xpress-decompress.c +++ b/src/xpress-decompress.c @@ -6,7 +6,7 @@ /* * - * Copyright (C) 2012, 2013 Biggers + * Copyright (C) 2012, 2013 Eric Biggers * * This file is part of wimlib, a library for working with WIM files. * @@ -91,9 +91,10 @@ * * Returns the match length, or -1 on error. */ -static int xpress_decode_match(unsigned huffsym, unsigned window_pos, - unsigned window_len, u8 window[], - struct input_bitstream *istream) +static int +xpress_decode_match(unsigned huffsym, unsigned window_pos, + unsigned window_len, u8 window[], + struct input_bitstream *istream) { unsigned match_len; unsigned match_offset; @@ -162,11 +163,12 @@ static int xpress_decode_match(unsigned huffsym, unsigned window_pos, /* Decodes the Huffman-encoded matches and literal bytes in a block of * XPRESS-encoded data. */ -static int xpress_decompress_block(struct input_bitstream *istream, - u8 uncompressed_data[], - unsigned uncompressed_len, - const u8 lens[], - const u16 decode_table[]) +static int +xpress_decompress_block(struct input_bitstream *istream, + u8 uncompressed_data[], + unsigned uncompressed_len, + const u8 lens[], + const u16 decode_table[]) { unsigned curpos; unsigned huffsym; @@ -178,7 +180,7 @@ static int xpress_decompress_block(struct input_bitstream *istream, ret = read_huffsym(istream, decode_table, lens, XPRESS_NUM_SYMBOLS, XPRESS_TABLEBITS, &huffsym, XPRESS_MAX_CODEWORD_LEN); - if (ret != 0) + if (ret) return ret; if (huffsym < XPRESS_NUM_CHARS) { @@ -198,8 +200,10 @@ static int xpress_decompress_block(struct input_bitstream *istream, } -int xpress_decompress(const void *__compressed_data, unsigned compressed_len, - void *uncompressed_data, unsigned uncompressed_len) +/* Documented in wimlib.h */ +WIMLIBAPI int +wimlib_xpress_decompress(const void *__compressed_data, unsigned compressed_len, + void *uncompressed_data, unsigned uncompressed_len) { u8 lens[XPRESS_NUM_SYMBOLS]; u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS]; @@ -219,8 +223,10 @@ int xpress_decompress(const void *__compressed_data, unsigned compressed_len, * code lengths of these symbols are given literally as 4-bit integers * in the first 256 bytes of the compressed data. */ - if (compressed_len < XPRESS_NUM_SYMBOLS / 2) + if (compressed_len < XPRESS_NUM_SYMBOLS / 2) { + ERROR("xpress_decompress(): Compressed length too short!"); return -1; + } for (i = 0; i < XPRESS_NUM_SYMBOLS / 2; i++) { *lens_p++ = compressed_data[i] & 0xf; @@ -230,7 +236,7 @@ int xpress_decompress(const void *__compressed_data, unsigned compressed_len, ret = make_huffman_decode_table(decode_table, XPRESS_NUM_SYMBOLS, XPRESS_TABLEBITS, lens, XPRESS_MAX_CODEWORD_LEN); - if (ret != 0) + if (ret) return ret; init_input_bitstream(&istream, compressed_data + XPRESS_NUM_SYMBOLS / 2,