summaryrefslogtreecommitdiffstats
path: root/contrib/bzip2/huffman.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2005-05-16 18:31:55 +0000
committerobrien <obrien@FreeBSD.org>2005-05-16 18:31:55 +0000
commit344ba35988e53bba3654f363d1bdcc39430247df (patch)
tree1ab456aa9146f4b57bf41375952059b5cceae392 /contrib/bzip2/huffman.c
parentb718740c2fa9f3e14e09fba90eca26f829b7d43a (diff)
downloadFreeBSD-src-344ba35988e53bba3654f363d1bdcc39430247df.zip
FreeBSD-src-344ba35988e53bba3654f363d1bdcc39430247df.tar.gz
Virgin import (trimmed) of Bzip2 version 1.0.3.
Diffstat (limited to 'contrib/bzip2/huffman.c')
-rw-r--r--contrib/bzip2/huffman.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/contrib/bzip2/huffman.c b/contrib/bzip2/huffman.c
index 293095c..5bf190b 100644
--- a/contrib/bzip2/huffman.c
+++ b/contrib/bzip2/huffman.c
@@ -8,7 +8,7 @@
This file is a part of bzip2 and/or libbzip2, a program and
library for lossless, block-sorting data compression.
- Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
+ Copyright (C) 1996-2005 Julian R Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -42,7 +42,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK.
- jseward@acm.org
+ jseward@bzip.org
bzip2/libbzip2 version 1.0 of 21 March 2000
This program is based on (at least) the work of:
@@ -162,7 +162,24 @@ void BZ2_hbMakeCodeLengths ( UChar *len,
if (! tooLong) break;
- for (i = 1; i < alphaSize; i++) {
+ /* 17 Oct 04: keep-going condition for the following loop used
+ to be 'i < alphaSize', which missed the last element,
+ theoretically leading to the possibility of the compressor
+ looping. However, this count-scaling step is only needed if
+ one of the generated Huffman code words is longer than
+ maxLen, which up to and including version 1.0.2 was 20 bits,
+ which is extremely unlikely. In version 1.0.3 maxLen was
+ changed to 17 bits, which has minimal effect on compression
+ ratio, but does mean this scaling step is used from time to
+ time, enough to verify that it works.
+
+ This means that bzip2-1.0.3 and later will only produce
+ Huffman codes with a maximum length of 17 bits. However, in
+ order to preserve backwards compatibility with bitstreams
+ produced by versions pre-1.0.3, the decompressor must still
+ handle lengths of up to 20. */
+
+ for (i = 1; i <= alphaSize; i++) {
j = weight[i] >> 8;
j = 1 + (j / 2);
weight[i] = j << 8;
OpenPOWER on IntegriCloud