]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed : contentSize + copyCCtx()
authorYann Collet <yann.collet.73@gmail.com>
Tue, 12 Apr 2016 17:13:08 +0000 (19:13 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 12 Apr 2016 17:13:08 +0000 (19:13 +0200)
lib/zstd_compress.c
programs/fuzzer.c

index 8bda0169ed4d6f51d0ef5fe90ddb5cdcfc81e41c..8ce18f81159c37c5a71a71b1bd4a646f637f3b01 100644 (file)
@@ -287,6 +287,7 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx)
 
     dstCCtx->hashLog3 = srcCCtx->hashLog3; /* must be before ZSTD_resetCCtx_advanced */
     ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, 0);
+    dstCCtx->params.fParams.contentSizeFlag = 0;   /* content size different from the one set during srcCCtx init */
 
     /* copy tables */
     {   const size_t chainSize = (srcCCtx->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->params.cParams.chainLog);
index 74fe1cac12424f3c7d5439de5332c6249dddfbb1..5bf532e1a0f5db982e84d2b161e5b0031e36fa55 100644 (file)
@@ -169,17 +169,15 @@ static int basicUnitTests(U32 seed, double compressibility)
     if (result != (size_t)-ZSTD_error_srcSize_wrong) goto _output_error;
     DISPLAYLEVEL(4, "OK \n");
 
-    /* Dictionary and Duplication tests */
+    /* Dictionary and CCtx Duplication tests */
     {   ZSTD_CCtx* ctxOrig = ZSTD_createCCtx();
         ZSTD_CCtx* ctxDuplicated = ZSTD_createCCtx();
         ZSTD_DCtx* dctx = ZSTD_createDCtx();
         size_t const dictSize = 500;
-        size_t cSizeOrig;
 
         DISPLAYLEVEL(4, "test%3i : copy context too soon : ", testNb++);
-        {   size_t const copyResult = ZSTD_copyCCtx(ctxDuplicated, ctxOrig);
-            if (!ZSTD_isError(copyResult)) goto _output_error;   /* error should be detected */
-        }
+        { size_t const copyResult = ZSTD_copyCCtx(ctxDuplicated, ctxOrig);
+          if (!ZSTD_isError(copyResult)) goto _output_error; }  /* error should be detected */
         DISPLAYLEVEL(4, "OK \n");
 
         DISPLAYLEVEL(4, "test%3i : load dictionary into context : ", testNb++);
@@ -209,15 +207,16 @@ static int basicUnitTests(U32 seed, double compressibility)
         DISPLAYLEVEL(4, "OK \n");
 
         DISPLAYLEVEL(4, "test%3i : compress with duplicated context : ", testNb++);
-        cSizeOrig = cSize;
-        cSize = 0;
-        result = ZSTD_compressContinue(ctxDuplicated, compressedBuffer, ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH), (const char*)CNBuffer + dictSize, COMPRESSIBLE_NOISE_LENGTH - dictSize);
-        if (ZSTD_isError(result)) goto _output_error;
-        cSize += result;
-        result = ZSTD_compressEnd(ctxDuplicated, (char*)compressedBuffer+cSize, ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH)-cSize);
-        if (ZSTD_isError(result)) goto _output_error;
-        cSize += result;
-        if (cSize != cSizeOrig) goto _output_error;   /* should be identical == have same size */
+        {   size_t const cSizeOrig = cSize;
+            cSize = 0;
+            result = ZSTD_compressContinue(ctxDuplicated, compressedBuffer, ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH), (const char*)CNBuffer + dictSize, COMPRESSIBLE_NOISE_LENGTH - dictSize);
+            if (ZSTD_isError(result)) goto _output_error;
+            cSize += result;
+            result = ZSTD_compressEnd(ctxDuplicated, (char*)compressedBuffer+cSize, ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH)-cSize);
+            if (ZSTD_isError(result)) goto _output_error;
+            cSize += result;
+            if (cSize != cSizeOrig) goto _output_error;   /* should be identical == have same size */
+        }
         DISPLAYLEVEL(4, "OK (%u bytes : %.2f%%)\n", (U32)cSize, (double)cSize/COMPRESSIBLE_NOISE_LENGTH*100);
 
         DISPLAYLEVEL(4, "test%3i : frame built with duplicated context should be decompressible : ", testNb++);