]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
ZDICT_finalizeDictionary() flipped comparison
authorNick Terrell <terrelln@fb.com>
Fri, 23 Dec 2016 02:01:14 +0000 (18:01 -0800)
committerNick Terrell <terrelln@fb.com>
Fri, 23 Dec 2016 02:01:14 +0000 (18:01 -0800)
`ZDICT_finalizeDictionary()` had a flipped comparison.
I also allowed `dictBufferCapacity == dictContentSize`.
It might be the case that the user wants to fill the dictionary
completely up, and then let zstd take exactly the space it needs
for the entropy tables.

lib/dictBuilder/zdict.c
lib/dictBuilder/zdict.h

index c3b227d745c75e301eb38d7de4bdc63c7d50e888..c5cf6f801fa4ca7b1e6b9be268563786d9ac2596 100644 (file)
@@ -837,7 +837,7 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
     U32 const notificationLevel = params.notificationLevel;
 
     /* check conditions */
-    if (dictBufferCapacity <= dictContentSize) return ERROR(dstSize_tooSmall);
+    if (dictBufferCapacity < dictContentSize) return ERROR(dstSize_tooSmall);
     if (dictContentSize < ZDICT_CONTENTSIZE_MIN) return ERROR(srcSize_wrong);
     if (dictBufferCapacity < ZDICT_DICTSIZE_MIN) return ERROR(dstSize_tooSmall);
 
@@ -863,7 +863,7 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
     }
 
     /* copy elements in final buffer ; note : src and dst buffer can overlap */
-    if (hSize + dictContentSize < dictBufferCapacity) dictContentSize = dictBufferCapacity - hSize;
+    if (hSize + dictContentSize > dictBufferCapacity) dictContentSize = dictBufferCapacity - hSize;
     {   size_t const dictSize = hSize + dictContentSize;
         char* dictEnd = (char*)dictBuffer + dictSize;
         memmove(dictEnd - dictContentSize, customDictContent, dictContentSize);
index 8dabfd5e5686b0f7245ea4e93f9d08cb9681cdeb..0641e36f64ea514b1856680ebf4aa6cf692258f9 100644 (file)
@@ -96,7 +96,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_advanced(void* dictBuffer, size_t dict
     supplied with an array of sizes `samplesSizes`, providing the size of each sample in order.
 
     dictContentSize must be > ZDICT_CONTENTSIZE_MIN bytes.
-    maxDictSize must be > dictContentSize, and must be > ZDICT_DICTSIZE_MIN bytes.
+    maxDictSize must be >= dictContentSize, and must be > ZDICT_DICTSIZE_MIN bytes.
 
     @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`),
               or an error code, which can be tested by ZDICT_isError().