lzx_write_compressed_tree(), lzx_read_code_lens(): Specify signed char
authorEric Biggers <ebiggers3@gmail.com>
Tue, 2 Jul 2013 02:32:40 +0000 (21:32 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 2 Jul 2013 02:58:14 +0000 (21:58 -0500)
The existing code specified just 'char' for a variable expected to be
signed, but the signedness of a 'char' is implementation-defined.  (In
fact, on ARM it is unsigned.)

src/lzx-compress.c
src/lzx-decompress.c

index a8e0340..61c4843 100644 (file)
@@ -425,7 +425,7 @@ lzx_write_compressed_tree(struct output_bitstream *out,
        unsigned i;
        unsigned len_in_run;
        unsigned additional_bits;
-       char delta;
+       signed char delta;
        u8 pretree_sym;
 
        ZERO_ARRAY(pretree_freqs);
@@ -502,7 +502,7 @@ lzx_write_compressed_tree(struct output_bitstream *out,
                         * */
                        while (cur_run_len >= 4) {
                                additional_bits = (cur_run_len > 4);
-                               delta = -(char)len_in_run;
+                               delta = -(signed char)len_in_run;
                                if (delta < 0)
                                        delta += 17;
                                pretree_freqs[19]++;
@@ -518,7 +518,7 @@ lzx_write_compressed_tree(struct output_bitstream *out,
                 * as a difference from the length of that codeword in the
                 * previous tree. */
                while (cur_run_len--) {
-                       delta = -(char)len_in_run;
+                       delta = -(signed char)len_in_run;
                        if (delta < 0)
                                delta += 17;
 
index 93ab841..1d0d04d 100644 (file)
@@ -244,7 +244,7 @@ lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
                unsigned num_zeroes;
                unsigned code;
                unsigned num_same;
-               char value;
+               signed char value;
 
                ret = read_huffsym_using_pretree(istream, pretree_decode_table,
                                                 pretree_lens, &tree_code);
@@ -284,7 +284,7 @@ lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
                                                         &code);
                        if (ret != 0)
                                return ret;
-                       value = (char)*lens - (char)code;
+                       value = (signed char)*lens - (signed char)code;
                        if (value < 0)
                                value += 17;
                        while (num_same--) {
@@ -294,7 +294,7 @@ lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
                        }
                        break;
                default: /* Difference from old length. */
-                       value = (char)*lens - (char)tree_code;
+                       value = (signed char)*lens - (signed char)tree_code;
                        if (value < 0)
                                value += 17;
                        *lens = value;