From: W. Felix Handte Date: Tue, 30 Jan 2018 20:22:29 +0000 (-0500) Subject: Avoid dictionary == NULL Check X-Git-Tag: upstream/1.9.3~8^2~41^2~1^2^2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6ed9a7799c35d9d259af36c3142739216ba8a58;p=platform%2Fupstream%2Flz4.git Avoid dictionary == NULL Check --- 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 (inputSizehashTable, 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;