From ed92ad52377e0ee686faec69ec5cbca291ab83c1 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 9 Jul 2016 10:01:20 -0500 Subject: [PATCH] lzx_common: add constant for maximum number of extra offset bits --- include/wimlib/lzx_constants.h | 5 +++++ src/lzx_compress.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/wimlib/lzx_constants.h b/include/wimlib/lzx_constants.h index 788eded8..20c4c624 100644 --- a/include/wimlib/lzx_constants.h +++ b/include/wimlib/lzx_constants.h @@ -72,6 +72,11 @@ /* The offset slot base for LZX_MIN_ALIGNED_OFFSET_SLOT. */ #define LZX_MIN_ALIGNED_OFFSET 14 +/* The maximum number of extra offset bits in verbatim blocks. (One would need + * to subtract LZX_NUM_ALIGNED_OFFSET_BITS to get the number of extra offset + * bits in *aligned* blocks.) */ +#define LZX_MAX_NUM_EXTRA_BITS 17 + /* Maximum lengths (in bits) for length-limited Huffman code construction. */ #define LZX_MAX_MAIN_CODEWORD_LEN 16 #define LZX_MAX_LEN_CODEWORD_LEN 16 diff --git a/src/lzx_compress.c b/src/lzx_compress.c index 8aff56f4..10b51902 100644 --- a/src/lzx_compress.c +++ b/src/lzx_compress.c @@ -976,8 +976,11 @@ lzx_write_sequences(struct lzx_output_bitstream *os, int block_type, extra_bits = adjusted_offset - (lzx_offset_slot_base[offset_slot] + LZX_OFFSET_ADJUSTMENT); - #define MAX_MATCH_BITS (MAIN_CODEWORD_LIMIT + LENGTH_CODEWORD_LIMIT + \ - 14 + ALIGNED_CODEWORD_LIMIT) + #define MAX_MATCH_BITS (MAIN_CODEWORD_LIMIT + \ + LENGTH_CODEWORD_LIMIT + \ + LZX_MAX_NUM_EXTRA_BITS - \ + LZX_NUM_ALIGNED_OFFSET_BITS + \ + ALIGNED_CODEWORD_LIMIT) /* Verify optimization is enabled on 64-bit */ STATIC_ASSERT(WORDBITS < 64 || CAN_BUFFER(MAX_MATCH_BITS)); @@ -1011,7 +1014,8 @@ lzx_write_sequences(struct lzx_output_bitstream *os, int block_type, lzx_add_bits(os, extra_bits >> LZX_NUM_ALIGNED_OFFSET_BITS, num_extra_bits - LZX_NUM_ALIGNED_OFFSET_BITS); if (!CAN_BUFFER(MAX_MATCH_BITS)) - lzx_flush_bits(os, 14); + lzx_flush_bits(os, LZX_MAX_NUM_EXTRA_BITS - + LZX_NUM_ALIGNED_OFFSET_BITS); lzx_add_bits(os, codes->codewords.aligned[adjusted_offset & LZX_ALIGNED_OFFSET_BITMASK], @@ -1020,11 +1024,11 @@ lzx_write_sequences(struct lzx_output_bitstream *os, int block_type, if (!CAN_BUFFER(MAX_MATCH_BITS)) lzx_flush_bits(os, ALIGNED_CODEWORD_LIMIT); } else { - STATIC_ASSERT(CAN_BUFFER(17)); + STATIC_ASSERT(CAN_BUFFER(LZX_MAX_NUM_EXTRA_BITS)); lzx_add_bits(os, extra_bits, num_extra_bits); if (!CAN_BUFFER(MAX_MATCH_BITS)) - lzx_flush_bits(os, 17); + lzx_flush_bits(os, LZX_MAX_NUM_EXTRA_BITS); } if (CAN_BUFFER(MAX_MATCH_BITS)) -- 2.43.0