]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Emit last literals of 0 size as well, to indicate block boundary
authorsenhuang42 <senhuang96@fb.com>
Thu, 29 Oct 2020 20:41:17 +0000 (16:41 -0400)
committersenhuang42 <senhuang96@fb.com>
Thu, 29 Oct 2020 20:41:17 +0000 (16:41 -0400)
lib/compress/zstd_compress.c

index f18880cab48e1dc36392fcf13ff1eebe99cd64a6..d5185dbde54cbe5c467d29be2b1641bf79de806c 100644 (file)
@@ -2489,14 +2489,16 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
         literalsRead += outSeqs[i].litLength;
     }
 
-    /* Insert last literals (if any exist) in the block as a sequence with ml == off == 0 */
+    /* Insert last literals (if any exist) in the block as a sequence with ml == off == 0.
+     * If there are no last literals, then we'll emit (of: 0, ml: 0, ll: 0), which is a marker
+     * for the block boundary, according to the API.
+     */
     assert(seqStoreLiteralsSize >= literalsRead);
     lastLLSize = seqStoreLiteralsSize - literalsRead;
-    if (lastLLSize > 0) {
-        outSeqs[i].litLength = (U32)lastLLSize;
-        outSeqs[i].matchLength = outSeqs[i].offset = outSeqs[i].rep = 0;
-        seqStoreSeqSize++;
-    }
+    outSeqs[i].litLength = (U32)lastLLSize;
+    outSeqs[i].matchLength = outSeqs[i].offset = outSeqs[i].rep = 0;
+    seqStoreSeqSize++;
+
     zc->seqCollector.seqIndex += seqStoreSeqSize;
 }