diff options
author | Nigel Tao <nigeltao@golang.org> | 2019-09-15 23:20:02 (GMT) |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2019-09-21 02:38:46 (GMT) |
commit | c5a83c1a48722108460f8542d92703fd5f59e296 (patch) | |
tree | aeb1cd1932b2452911265d235027a0d0ff60d767 /lib/lz4.c | |
parent | 9b2b96edc4642c4a21e2485ffe9bd43ed5f3a2b2 (diff) | |
download | lz4-c5a83c1a48722108460f8542d92703fd5f59e296.zip lz4-c5a83c1a48722108460f8542d92703fd5f59e296.tar.gz lz4-c5a83c1a48722108460f8542d92703fd5f59e296.tar.bz2 |
Have read_variable_length use fixed size types
Otherwise, the output from decoding LZ4-compressed input could be
platform dependent.
Also add a compile-time check to confirm the existing code's assumptions
that, if <stdint.h> isn't used, then sizeof(int) == 4.
Updates #792
Diffstat (limited to 'lib/lz4.c')
-rw-r--r-- | lib/lz4.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -249,6 +249,10 @@ static int g_debuglog_enable = 1; typedef uint64_t U64; typedef uintptr_t uptrval; #else +# include <limits.h> +# if UINT_MAX != 4294967295UL +# error "LZ4 code (when not C++ or C99) assumes that sizeof(int) == 4" +# endif typedef unsigned char BYTE; typedef unsigned short U16; typedef unsigned int U32; @@ -1625,8 +1629,8 @@ typedef enum { loop_error = -2, initial_error = -1, ok = 0 } variable_length_err LZ4_FORCE_INLINE unsigned read_variable_length(const BYTE**ip, const BYTE* lencheck, int loop_check, int initial_check, variable_length_error* error) { - unsigned length = 0; - unsigned s; + U32 length = 0; + U32 s; if (initial_check && unlikely((*ip) >= lencheck)) { /* overflow detection */ *error = initial_error; return length; |