diff options
author | David Cole <david.cole@kitware.com> | 2007-09-11 15:22:29 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2007-09-11 15:22:29 (GMT) |
commit | 3edcd70754afe7c6b2ff71e0010c6b3d64b4fe37 (patch) | |
tree | 0dca962765d94496432c628b96dbfeef7a252064 /Utilities/cmzlib/trees.c | |
parent | f262298bb037b683c995f239d1ca9fc00aaec3f3 (diff) | |
download | CMake-3edcd70754afe7c6b2ff71e0010c6b3d64b4fe37.zip CMake-3edcd70754afe7c6b2ff71e0010c6b3d64b4fe37.tar.gz CMake-3edcd70754afe7c6b2ff71e0010c6b3d64b4fe37.tar.bz2 |
ENH: Update zlib to 1.2.3. Addresses bugs #5445 and #3473.
Diffstat (limited to 'Utilities/cmzlib/trees.c')
-rw-r--r-- | Utilities/cmzlib/trees.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/Utilities/cmzlib/trees.c b/Utilities/cmzlib/trees.c index 19d0374..395e4e1 100644 --- a/Utilities/cmzlib/trees.c +++ b/Utilities/cmzlib/trees.c @@ -1,6 +1,6 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2002 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h + * Copyright (C) 1995-2005 Jean-loup Gailly + * For conditions of distribution and use, see copyright notice in zlib.h */ /* @@ -230,7 +230,6 @@ local void send_bits(s, value, length) #endif /* DEBUG */ -#define MAX(a,b) (a >= b ? a : b) /* the arguments must not have side effects */ /* =========================================================================== @@ -556,7 +555,7 @@ local void gen_bitlen(s, desc) while (n != 0) { m = s->heap[--h]; if (m > max_code) continue; - if (tree[m].Len != (unsigned) bits) { + if ((unsigned) tree[m].Len != (unsigned) bits) { Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); s->opt_len += ((long)bits - (long)tree[m].Len) *(long)tree[m].Freq; @@ -675,7 +674,8 @@ local void build_tree(s, desc) /* Create a new node father of n and m */ tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch) (MAX(s->depth[n], s->depth[m]) + 1); + s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? + s->depth[n] : s->depth[m]) + 1); tree[n].Dad = tree[m].Dad = (ush)node; #ifdef DUMP_BL_TREE if (tree == s->bl_tree) { @@ -930,8 +930,9 @@ void _tr_flush_block(s, buf, stored_len, eof) /* Build the Huffman trees unless a stored block is forced */ if (s->level > 0) { - /* Check if the file is ascii or binary */ - if (s->data_type == Z_UNKNOWN) set_data_type(s); + /* Check if the file is binary or text */ + if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN) + set_data_type(s); /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); @@ -950,7 +951,7 @@ void _tr_flush_block(s, buf, stored_len, eof) */ max_blindex = build_bl_tree(s); - /* Determine the best encoding. Compute first the block length in bytes*/ + /* Determine the best encoding. Compute the block lengths in bytes. */ opt_lenb = (s->opt_len+3+7)>>3; static_lenb = (s->static_len+3+7)>>3; @@ -982,7 +983,7 @@ void _tr_flush_block(s, buf, stored_len, eof) #ifdef FORCE_STATIC } else if (static_lenb >= 0) { /* force static trees */ #else - } else if (static_lenb == opt_lenb) { + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { #endif send_bits(s, (STATIC_TREES<<1)+eof, 3); compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); @@ -1107,7 +1108,8 @@ local void compress_block(s, ltree, dtree) } /* literal or match pair ? */ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); + Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + "pendingBuf overflow"); } while (lx < s->last_lit); @@ -1116,21 +1118,24 @@ local void compress_block(s, ltree, dtree) } /* =========================================================================== - * Set the data type to ASCII or BINARY, using a crude approximation: - * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. - * IN assertion: the fields freq of dyn_ltree are set and the total of all - * frequencies does not exceed 64K (to fit in an int on 16 bit machines). + * Set the data type to BINARY or TEXT, using a crude approximation: + * set it to Z_TEXT if all symbols are either printable characters (33 to 255) + * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. + * IN assertion: the fields Freq of dyn_ltree are set. */ local void set_data_type(s) deflate_state *s; { - int n = 0; - unsigned ascii_freq = 0; - unsigned bin_freq = 0; - while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; - while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; - while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); + int n; + + for (n = 0; n < 9; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + if (n == 9) + for (n = 14; n < 32; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY; } /* =========================================================================== @@ -1199,7 +1204,7 @@ local void copy_block(s, buf, len, header) s->last_eob_len = 8; /* enough lookahead for inflate */ if (header) { - put_short(s, (ush)len); + put_short(s, (ush)len); put_short(s, (ush)~len); #ifdef DEBUG s->bits_sent += 2*16; |