From: Nathan Moinvaziri Date: Fri, 7 Feb 2020 23:01:10 +0000 (-0800) Subject: Fixed missing compressed_len count in deflate_quick when ZLIB_DEBUG defined. Put... X-Git-Tag: 1.9.9-b1~358 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2304c7fc00933d02a871acfd57601df2c49b35c;p=thirdparty%2Fzlib-ng.git Fixed missing compressed_len count in deflate_quick when ZLIB_DEBUG defined. Put most likely condition in send_bits first. --- diff --git a/arch/x86/deflate_quick.c b/arch/x86/deflate_quick.c index f79d20fc..9f6d6b6d 100644 --- a/arch/x86/deflate_quick.c +++ b/arch/x86/deflate_quick.c @@ -135,6 +135,9 @@ static inline void static_emit_ptr(deflate_state *const s, const int lc, const u send_bits(s, code1, len1, bi_buf, bi_valid); send_bits(s, code2, len2, bi_buf, bi_valid); +#ifdef ZLIB_DEBUG + s->compressed_len += len1 + len2; +#endif s->bi_valid = bi_valid; s->bi_buf = bi_buf; @@ -147,6 +150,9 @@ static inline void static_emit_lit(deflate_state *const s, const int lit) { uint32_t bi_buf = s->bi_buf; send_bits(s, static_ltree[lit].Code, static_ltree[lit].Len, bi_buf, bi_valid); +#ifdef ZLIB_DEBUG + s->compressed_len += static_ltree[lit].Len; +#endif s->bi_valid = bi_valid; s->bi_buf = bi_buf; diff --git a/deflate.h b/deflate.h index 8032fccb..275261e0 100644 --- a/deflate.h +++ b/deflate.h @@ -473,7 +473,7 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[]; #ifdef ZLIB_DEBUG # define send_debug_trace(s, value, length) {\ Tracevv((stderr, " l %2d v %4x ", length, value));\ - Assert(length > 0 && length <= BIT_BUF_SIZE - 1, "invalid length");\ + Assert(length > 0 && length <= BIT_BUF_SIZE, "invalid length");\ s->bits_sent += (unsigned long)length;\ } #else @@ -488,19 +488,18 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[]; uint32_t val = (uint32_t)t_val;\ uint32_t len = (uint32_t)t_len;\ send_debug_trace(s, val, len);\ - if (bits_valid == BIT_BUF_SIZE) {\ + if (bits_valid + len < BIT_BUF_SIZE) {\ + bit_buf |= val << bits_valid;\ + bits_valid += len;\ + } else if (bits_valid == BIT_BUF_SIZE) {\ put_uint32(s, bit_buf);\ bit_buf = val;\ bits_valid = len;\ - } else if (bits_valid + len >= BIT_BUF_SIZE) {\ + } else {\ bit_buf |= val << bits_valid;\ put_uint32(s, bit_buf);\ bit_buf = val >> (BIT_BUF_SIZE - bits_valid);\ bits_valid += len - BIT_BUF_SIZE;\ - } else {\ - bit_buf |= val << bits_valid;\ - bits_valid += len;\ }\ } - #endif /* DEFLATE_H_ */