diff options
author | qiuyangs <sunqiuyang@huawei.com> | 2019-01-06 08:29:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-06 08:29:30 (GMT) |
commit | 660d21272e4c8a0f49db5fc1e6853f08713dff82 (patch) | |
tree | 7e203a18a79fd67779f3dce22e0a3df39b27b2a8 /lib | |
parent | ec735ac53e6b216efcbcd411d496dc90b058c570 (diff) | |
download | lz4-660d21272e4c8a0f49db5fc1e6853f08713dff82.zip lz4-660d21272e4c8a0f49db5fc1e6853f08713dff82.tar.gz lz4-660d21272e4c8a0f49db5fc1e6853f08713dff82.tar.bz2 |
lz4hc.c: change (length >> 8) to (length / 255)
Every 0xff byte in the compressed block corresponds to a length of 255 (not 256) in the input data. For long repeating sequences, using (length >> 8) may generate bad compressed blocks.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4hc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 56c8f47..86db155 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -437,7 +437,7 @@ LZ4_FORCE_INLINE int LZ4HC_encodeSequence ( /* Encode Literal length */ length = (size_t)(*ip - *anchor); - if ((limit) && ((*op + (length >> 8) + length + (2 + 1 + LASTLITERALS)) > oend)) return 1; /* Check output limit */ + if ((limit) && ((*op + (length / 255) + length + (2 + 1 + LASTLITERALS)) > oend)) return 1; /* Check output limit */ if (length >= RUN_MASK) { size_t len = length - RUN_MASK; *token = (RUN_MASK << ML_BITS); @@ -458,7 +458,7 @@ LZ4_FORCE_INLINE int LZ4HC_encodeSequence ( /* Encode MatchLength */ assert(matchLength >= MINMATCH); length = (size_t)(matchLength - MINMATCH); - if ((limit) && (*op + (length >> 8) + (1 + LASTLITERALS) > oend)) return 1; /* Check output limit */ + if ((limit) && (*op + (length / 255) + (1 + LASTLITERALS) > oend)) return 1; /* Check output limit */ if (length >= ML_MASK) { *token += ML_MASK; length -= ML_MASK; |