]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use temp variables in send_all_trees too
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 17 Sep 2019 13:48:03 +0000 (15:48 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 22 Oct 2019 07:17:22 +0000 (09:17 +0200)
Re-introduce private temp variables for val and len in send_bits macro.

deflate.h
trees.c

index fe8a80a1652c6f3bf6a6859dc898b389e46875f4..9db03fbe62010a533f39f49c56e2462558f693d7 100644 (file)
--- 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 21135f18377c4f29d3da268388cfb577a06ef4ed..bec889b0e9f6464bebbf6a0b5724457bc631c798 100644 (file)
--- 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));