summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Felix Handte <w@felixhandte.com>2019-08-06 23:08:41 (GMT)
committerW. Felix Handte <w@felixhandte.com>2019-08-06 23:08:41 (GMT)
commit4c580067199c4a7fdcacc6961842ee6d3832bb93 (patch)
tree718b41f2409059aa4c3acb6ba22c8c98b4d16a51
parent4f49d744e8de26b4d942c0c0e480f6a37dde41a5 (diff)
downloadlz4-4c580067199c4a7fdcacc6961842ee6d3832bb93.zip
lz4-4c580067199c4a7fdcacc6961842ee6d3832bb93.tar.gz
lz4-4c580067199c4a7fdcacc6961842ee6d3832bb93.tar.bz2
Only Bump Offset When Attaching Non-Null Dictionary
We do want to bump, even if the dictionary is empty, but we **don't** want to bump if the dictionary is null.
-rw-r--r--lib/lz4.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 07739a7..877d14e 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1429,9 +1429,12 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
}
void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream) {
- DEBUGLOG(4, "LZ4_attach_dictionary (%p, %p, size %d)",
- workingStream, dictionaryStream, dictionaryStream != NULL ?
- dictionaryStream->internal_donotuse.dictSize : 0);
+ const LZ4_stream_t_internal* dictCtx = dictionaryStream == NULL ? NULL :
+ &(dictionaryStream->internal_donotuse);
+
+ DEBUGLOG(4, "LZ4_attach_dictionary (%p, %p, size %u)",
+ workingStream, dictionaryStream,
+ dictCtx != NULL ? dictCtx->dictSize : 0);
/* Calling LZ4_resetStream_fast() here makes sure that changes will not be
* erased by subsequent calls to LZ4_resetStream_fast() in case stream was
@@ -1439,20 +1442,23 @@ void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dict
*/
LZ4_resetStream_fast(workingStream);
- /* If the current offset is zero, we will never look in the
- * external dictionary context, since there is no value a table
- * entry can take that indicate a miss. In that case, we need
- * to bump the offset to something non-zero.
- */
- if (workingStream->internal_donotuse.currentOffset == 0) {
- workingStream->internal_donotuse.currentOffset = 64 KB;
- }
+ if (dictCtx != NULL) {
+ /* If the current offset is zero, we will never look in the
+ * external dictionary context, since there is no value a table
+ * entry can take that indicate a miss. In that case, we need
+ * to bump the offset to something non-zero.
+ */
+ if (workingStream->internal_donotuse.currentOffset == 0) {
+ workingStream->internal_donotuse.currentOffset = 64 KB;
+ }
- if (dictionaryStream != NULL && dictionaryStream->internal_donotuse.dictSize > 0) {
- workingStream->internal_donotuse.dictCtx = &(dictionaryStream->internal_donotuse);
- } else {
- workingStream->internal_donotuse.dictCtx = NULL;
+ /* Don't actually attach an empty dictionary.
+ */
+ if (dictCtx->dictSize == 0) {
+ dictCtx = NULL;
+ }
}
+ workingStream->internal_donotuse.dictCtx = dictCtx;
}