summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2018-01-30 20:22:29 (GMT)
committerW. Felix Handte <w@felixhandte.com>2018-03-12 18:58:43 (GMT)
commitd6ed9a7799c35d9d259af36c3142739216ba8a58 (patch)
tree643da6b13501de4438026e770c0cd1295e2f8bf4
parentefc419a6d4448a5806715e967384ea85f880fe59 (diff)
downloadlz4-d6ed9a7799c35d9d259af36c3142739216ba8a58.zip
lz4-d6ed9a7799c35d9d259af36c3142739216ba8a58.tar.gz
lz4-d6ed9a7799c35d9d259af36c3142739216ba8a58.tar.bz2
Avoid dictionary == NULL Check
-rw-r--r--lib/lz4.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 990096c..3e456ac 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -590,6 +590,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
(const BYTE*) source - dictCtx->currentOffset :
(const BYTE*) source - dictSize - currentOffset;
const ptrdiff_t dictDelta = dictionary ? dictEnd - (const BYTE*) source : 0;
+ const BYTE* dictLowLimit;
BYTE* op = (BYTE*) dest;
BYTE* const olimit = op + maxOutputSize;
@@ -619,6 +620,9 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
lowLimit = (const BYTE*)source;
break;
}
+
+ dictLowLimit = dictionary ? dictionary : lowLimit;
+
if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) return 0; /* Size too large (not within 64K limit) */
if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
@@ -653,15 +657,15 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
/* TODO: use precalc-ed hash? */
match = LZ4_getPosition(ip, dictCtx->hashTable, byU32, dictBase);
refDelta = dictDelta;
- lowLimit = dictionary;
+ lowLimit = dictLowLimit;
} else {
refDelta = 0;
lowLimit = (const BYTE*)source;
}
} else if (dictDirective==usingExtDict) {
- if (match < (const BYTE*)source && dictionary != NULL) {
+ if (match < (const BYTE*)source) {
refDelta = dictDelta;
- lowLimit = dictionary;
+ lowLimit = dictLowLimit;
} else {
refDelta = 0;
lowLimit = (const BYTE*)source;
@@ -703,7 +707,7 @@ _next_match:
/* Encode MatchLength */
{ unsigned matchCode;
- if ((dictDirective==usingExtDict || dictDirective==usingExtDictCtx) && (dictionary != NULL) && (lowLimit==dictionary)) {
+ if ((dictDirective==usingExtDict || dictDirective==usingExtDictCtx) && (dictionary != NULL) && (lowLimit==dictLowLimit)) {
const BYTE* limit;
match += refDelta;
limit = ip + (dictEnd-match);
@@ -754,15 +758,15 @@ _next_match:
/* TODO: use precalc-ed hash? */
match = LZ4_getPosition(ip, dictCtx->hashTable, byU32, dictBase);
refDelta = dictDelta;
- lowLimit = dictionary;
+ lowLimit = dictLowLimit;
} else {
refDelta = 0;
lowLimit = (const BYTE*)source;
}
} else if (dictDirective==usingExtDict) {
- if (match < (const BYTE*)source && dictionary != NULL) {
+ if (match < (const BYTE*)source) {
refDelta = dictDelta;
- lowLimit = dictionary;
+ lowLimit = dictLowLimit;
} else {
refDelta = 0;
lowLimit = (const BYTE*)source;