summaryrefslogtreecommitdiffstats
path: root/lib/lz4.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-09-28 04:04:40 (GMT)
committerYann Collet <cyan@fb.com>2020-09-28 04:04:40 (GMT)
commite7fe105ac6ed02019d34731d2ba3aceb11b51bb1 (patch)
treeaead7ea0a02aed25e39e30ed3c525cd3ee6cfa30 /lib/lz4.c
parent20856da7c571cc1ee55965a342527f8263dc356d (diff)
downloadlz4-e7fe105ac6ed02019d34731d2ba3aceb11b51bb1.zip
lz4-e7fe105ac6ed02019d34731d2ba3aceb11b51bb1.tar.gz
lz4-e7fe105ac6ed02019d34731d2ba3aceb11b51bb1.tar.bz2
fix efficiency of LZ4_compress_HC_destSize()
LZ4_compress_HC_destSize() had a tendency to discard its last match when this match overflowed specified dstBuffer limit. The impact is generally moderate, but occasionally huge, typically when this last match is very large (such as compressing a bunch of zeroes). Issue #784 fixed for both Chain and Opt implementations. Added a unit test suggested by @remittor checking this topic.
Diffstat (limited to 'lib/lz4.c')
-rw-r--r--lib/lz4.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 2222d53..c192d5b 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -247,6 +247,7 @@ static const int LZ4_minLength = (MFLIMIT+1);
/*-************************************
* Types
**************************************/
+#include <limits.h>
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
# include <stdint.h>
typedef uint8_t BYTE;
@@ -256,7 +257,6 @@ static const int LZ4_minLength = (MFLIMIT+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
@@ -1192,6 +1192,7 @@ _last_literals:
return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
}
}
+ DEBUGLOG(6, "Final literal run : %i literals", (int)lastRun);
if (lastRun >= RUN_MASK) {
size_t accumulator = lastRun - RUN_MASK;
*op++ = RUN_MASK << ML_BITS;