diff options
Diffstat (limited to 'trees.c')
-rw-r--r-- | trees.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -213,7 +213,7 @@ local void send_bits(s, value, length) | |||
213 | #define send_bits(s, value, length) \ | 213 | #define send_bits(s, value, length) \ |
214 | { int len = length;\ | 214 | { int len = length;\ |
215 | if (s->bi_valid > (int)Buf_size - len) {\ | 215 | if (s->bi_valid > (int)Buf_size - len) {\ |
216 | int val = value;\ | 216 | int val = (int)value;\ |
217 | s->bi_buf |= (ush)val << s->bi_valid;\ | 217 | s->bi_buf |= (ush)val << s->bi_valid;\ |
218 | put_short(s, s->bi_buf);\ | 218 | put_short(s, s->bi_buf);\ |
219 | s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ | 219 | s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ |
@@ -522,8 +522,8 @@ local void gen_bitlen(s, desc) | |||
522 | xbits = 0; | 522 | xbits = 0; |
523 | if (n >= base) xbits = extra[n-base]; | 523 | if (n >= base) xbits = extra[n-base]; |
524 | f = tree[n].Freq; | 524 | f = tree[n].Freq; |
525 | s->opt_len += (ulg)f * (bits + xbits); | 525 | s->opt_len += (ulg)f * (unsigned)(bits + xbits); |
526 | if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); | 526 | if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits); |
527 | } | 527 | } |
528 | if (overflow == 0) return; | 528 | if (overflow == 0) return; |
529 | 529 | ||
@@ -555,8 +555,7 @@ local void gen_bitlen(s, desc) | |||
555 | if (m > max_code) continue; | 555 | if (m > max_code) continue; |
556 | if ((unsigned) tree[m].Len != (unsigned) bits) { | 556 | if ((unsigned) tree[m].Len != (unsigned) bits) { |
557 | Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); | 557 | Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); |
558 | s->opt_len += ((long)bits - (long)tree[m].Len) | 558 | s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq; |
559 | *(long)tree[m].Freq; | ||
560 | tree[m].Len = (ush)bits; | 559 | tree[m].Len = (ush)bits; |
561 | } | 560 | } |
562 | n--; | 561 | n--; |
@@ -578,7 +577,7 @@ local void gen_codes (tree, max_code, bl_count) | |||
578 | ushf *bl_count; /* number of codes at each bit length */ | 577 | ushf *bl_count; /* number of codes at each bit length */ |
579 | { | 578 | { |
580 | ush next_code[MAX_BITS+1]; /* next code value for each bit length */ | 579 | ush next_code[MAX_BITS+1]; /* next code value for each bit length */ |
581 | ush code = 0; /* running code value */ | 580 | unsigned code = 0; /* running code value */ |
582 | int bits; /* bit index */ | 581 | int bits; /* bit index */ |
583 | int n; /* code index */ | 582 | int n; /* code index */ |
584 | 583 | ||
@@ -586,7 +585,8 @@ local void gen_codes (tree, max_code, bl_count) | |||
586 | * without bit reversal. | 585 | * without bit reversal. |
587 | */ | 586 | */ |
588 | for (bits = 1; bits <= MAX_BITS; bits++) { | 587 | for (bits = 1; bits <= MAX_BITS; bits++) { |
589 | next_code[bits] = code = (code + bl_count[bits-1]) << 1; | 588 | code = (code + bl_count[bits-1]) << 1; |
589 | next_code[bits] = (ush)code; | ||
590 | } | 590 | } |
591 | /* Check that the bit counts in bl_count are consistent. The last code | 591 | /* Check that the bit counts in bl_count are consistent. The last code |
592 | * must be all ones. | 592 | * must be all ones. |
@@ -599,7 +599,7 @@ local void gen_codes (tree, max_code, bl_count) | |||
599 | int len = tree[n].Len; | 599 | int len = tree[n].Len; |
600 | if (len == 0) continue; | 600 | if (len == 0) continue; |
601 | /* Now reverse the bits */ | 601 | /* Now reverse the bits */ |
602 | tree[n].Code = bi_reverse(next_code[len]++, len); | 602 | tree[n].Code = (ush)bi_reverse(next_code[len]++, len); |
603 | 603 | ||
604 | Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", | 604 | Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", |
605 | n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); | 605 | n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); |
@@ -821,7 +821,7 @@ local int build_bl_tree(s) | |||
821 | if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; | 821 | if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; |
822 | } | 822 | } |
823 | /* Update opt_len to include the bit length tree and counts */ | 823 | /* Update opt_len to include the bit length tree and counts */ |
824 | s->opt_len += 3*(max_blindex+1) + 5+5+4; | 824 | s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4; |
825 | Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", | 825 | Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", |
826 | s->opt_len, s->static_len)); | 826 | s->opt_len, s->static_len)); |
827 | 827 | ||
@@ -1090,7 +1090,7 @@ local void compress_block(s, ltree, dtree) | |||
1090 | send_code(s, code, dtree); /* send the distance code */ | 1090 | send_code(s, code, dtree); /* send the distance code */ |
1091 | extra = extra_dbits[code]; | 1091 | extra = extra_dbits[code]; |
1092 | if (extra != 0) { | 1092 | if (extra != 0) { |
1093 | dist -= base_dist[code]; | 1093 | dist -= (unsigned)base_dist[code]; |
1094 | send_bits(s, dist, extra); /* send the extra distance bits */ | 1094 | send_bits(s, dist, extra); /* send the extra distance bits */ |
1095 | } | 1095 | } |
1096 | } /* literal or match pair ? */ | 1096 | } /* literal or match pair ? */ |