]> wimlib.net Git - wimlib/blobdiff - src/compress_common.c
Merge compression updates
[wimlib] / src / compress_common.c
index e8ed00d3c3096e810b46d67ef4617d5196618058..1653b04f2362db20838447442149badb09707c58 100644 (file)
@@ -2,25 +2,12 @@
  * compress_common.c
  *
  * Code for compression shared among multiple compression formats.
- */
-
-/*
- * Copyright (C) 2012, 2013, 2014 Eric Biggers
- *
- * This file is part of wimlib, a library for working with WIM files.
- *
- * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
  *
- * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
+ * Author:  Eric Biggers
+ * Year:    2012 - 2014
  *
- * You should have received a copy of the GNU General Public License
- * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ * The author dedicates this file to the public domain.
+ * You can do whatever you want with this file.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -33,7 +20,6 @@
 #include "wimlib/compress_common.h"
 #include "wimlib/util.h"
 
-#include <stdlib.h>
 #include <string.h>
 
 /* Writes @num_bits bits, given by the @num_bits least significant bits of
@@ -94,11 +80,11 @@ bitstream_put_byte(struct output_bitstream *ostream, u8 n)
  *
  * Returns -1 if the stream has overrun; otherwise returns the total number of
  * bytes in the output.  */
-input_idx_t
+u32
 flush_output_bitstream(struct output_bitstream *ostream)
 {
        if (unlikely(ostream->overrun))
-               return ~(input_idx_t)0;
+               return (u32)~0UL;
 
        *(le16*)ostream->bit_output =
                cpu_to_le16((u16)((u32)ostream->bitbuf << ostream->free_bits));
@@ -553,8 +539,8 @@ gen_codewords(u32 A[restrict], u8 lens[restrict],
  * approximately (with the algorithm used here) the minimum weighted path
  * length from the root, given this constraint.
  *
- * A canonical Huffman code satisfies the properties that a codeword
- * never lexicographically precedes a shorter codeword, and the
+ * A canonical Huffman code satisfies the properties that a longer
+ * codeword never lexicographically precedes a shorter codeword, and the
  * lexicographic ordering of codewords of the same length is the same as
  * the lexicographic ordering of the corresponding symbols.  A canonical
  * Huffman code, or more generally a canonical prefix code, can be
@@ -690,7 +676,7 @@ make_canonical_huffman_code(unsigned num_syms, unsigned max_codeword_len,
        /* Assumptions  */
        wimlib_assert2(num_syms >= 2);
        wimlib_assert2(num_syms <= (1 << NUM_SYMBOL_BITS));
-       wimlib_assert2(max_codeword_len > 0);
+       wimlib_assert2((1ULL << max_codeword_len) >= num_syms);
        wimlib_assert2(max_codeword_len <= 32);
 
        /* We begin by sorting the symbols primarily by frequency and