Skip to content

Commit edbfb28

Browse files
committed
Use temp variables in send_all_trees too
Re-introduce private temp variables for val and len in send_bits macro.
1 parent bcb7a0b commit edbfb28

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

deflate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm);
437437
* (16 - bit_valid) bits from value, leaving (width - (16-bit_valid))
438438
* unused bits in value.
439439
*/
440-
#define send_bits(s, val, len, bit_buf, bits_valid) {\
440+
#define send_bits(s, t_val, t_len, bit_buf, bits_valid) {\
441+
int val = t_val;\
442+
int len = t_len;\
441443
send_debug_trace(s, val, len);\
442444
if (bits_valid > (int)Buf_size - len) {\
443445
bit_buf |= (uint16_t)val << bits_valid;\

trees.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,16 +563,25 @@ static void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes
563563

564564
Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
565565
Assert(lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes");
566+
567+
// Temp local variables
568+
int filled = s->bi_valid;
569+
uint16_t bit_buf = s->bi_buf;
570+
566571
Tracev((stderr, "\nbl counts: "));
567-
send_bits(s, lcodes-257, 5, s->bi_buf, s->bi_valid); /* not +255 as stated in appnote.txt */
568-
send_bits(s, dcodes-1, 5, s->bi_buf, s->bi_valid);
569-
send_bits(s, blcodes-4, 4, s->bi_buf, s->bi_valid); /* not -3 as stated in appnote.txt */
572+
send_bits(s, lcodes-257, 5, bit_buf, filled); /* not +255 as stated in appnote.txt */
573+
send_bits(s, dcodes-1, 5, bit_buf, filled);
574+
send_bits(s, blcodes-4, 4, bit_buf, filled); /* not -3 as stated in appnote.txt */
570575
for (rank = 0; rank < blcodes; rank++) {
571576
Tracev((stderr, "\nbl code %2u ", bl_order[rank]));
572-
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3, s->bi_buf, s->bi_valid);
577+
send_bits(s, s->bl_tree[bl_order[rank]].Len, 3, bit_buf, filled);
573578
}
574579
Tracev((stderr, "\nbl tree: sent %lu", s->bits_sent));
575580

581+
// Store back temp variables
582+
s->bi_buf = bit_buf;
583+
s->bi_valid = filled;
584+
576585
send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
577586
Tracev((stderr, "\nlit tree: sent %lu", s->bits_sent));
578587

0 commit comments

Comments
 (0)