From: Hans Kristian Rosbach Date: Tue, 17 Sep 2019 13:48:03 +0000 (+0200) Subject: Use temp variables in send_all_trees too X-Git-Tag: 1.9.9-b1~404 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=edbfb283977a19d1d6c80d78b9d761dd545c8071;p=thirdparty%2Fzlib-ng.git Use temp variables in send_all_trees too Re-introduce private temp variables for val and len in send_bits macro. --- diff --git a/deflate.h b/deflate.h index fe8a80a1..9db03fbe 100644 --- a/deflate.h +++ b/deflate.h @@ -437,7 +437,9 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm); * (16 - bit_valid) bits from value, leaving (width - (16-bit_valid)) * unused bits in value. */ -#define send_bits(s, val, len, bit_buf, bits_valid) {\ +#define send_bits(s, t_val, t_len, bit_buf, bits_valid) {\ + int val = t_val;\ + int len = t_len;\ send_debug_trace(s, val, len);\ if (bits_valid > (int)Buf_size - len) {\ bit_buf |= (uint16_t)val << bits_valid;\ diff --git a/trees.c b/trees.c index 21135f18..bec889b0 100644 --- a/trees.c +++ b/trees.c @@ -563,16 +563,25 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); Assert(lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes"); + + // Temp local variables + int filled = s->bi_valid; + uint16_t bit_buf = s->bi_buf; + Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5, s->bi_buf, s->bi_valid); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5, s->bi_buf, s->bi_valid); - send_bits(s, blcodes-4, 4, s->bi_buf, s->bi_valid); /* not -3 as stated in appnote.txt */ + send_bits(s, lcodes-257, 5, bit_buf, filled); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5, bit_buf, filled); + send_bits(s, blcodes-4, 4, bit_buf, filled); /* not -3 as stated in appnote.txt */ for (rank = 0; rank < blcodes; rank++) { Tracev((stderr, "\nbl code %2u ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3, s->bi_buf, s->bi_valid); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3, bit_buf, filled); } Tracev((stderr, "\nbl tree: sent %lu", s->bits_sent)); + // Store back temp variables + s->bi_buf = bit_buf; + s->bi_valid = filled; + send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ Tracev((stderr, "\nlit tree: sent %lu", s->bits_sent));