]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Constifying, malloc check and naming nit 1928/head
authorBimba Shrestha <bimbashrestha@fb.com>
Wed, 18 Dec 2019 01:16:51 +0000 (17:16 -0800)
committerBimba Shrestha <bimbashrestha@fb.com>
Wed, 18 Dec 2019 01:16:51 +0000 (17:16 -0800)
lib/compress/zstd_compress.c
tests/fuzzer.c

index 338f8dd5662e807830f5409aa28f390435877b6b..a674cea402283948e9c7ac2a728475ca47fc4997 100644 (file)
@@ -2568,7 +2568,7 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx,
      * greater than the optimistic number of blocks we still have remaining.
      * This might be UNset when data is uncompressable and we're streaming.  */
 
-    int enoughDstCapacityForNoCompressSuperBlocks =
+    const int enoughDstCapacityForNoCompressSuperBlocks =
         (dstCapacity / (blockSize + 7 /* header + checksum */)) > (srcSize / blockSize);
     assert(cctx->appliedParams.cParams.windowLog <= ZSTD_WINDOWLOG_MAX);
 
index 7880c5d43beca8e3524ed08be825bcff81c8f885..337455d9f7140deb5c10ba586e986c13127dd4ab 100644 (file)
@@ -489,10 +489,10 @@ static int basicUnitTests(U32 const seed, double compressibility)
     }
     DISPLAYLEVEL(3, "OK \n");
 
-    DISPLAYLEVEL(3, "test%3d: superblock uncompressable data, too many nocompress superblocks : ", testNb++)
+    DISPLAYLEVEL(3, "test%3d: superblock uncompressible data, too many nocompress superblocks : ", testNb++)
     {
-        ZSTD_CCtx* cctx = ZSTD_createCCtx();
-        BYTE* src = (BYTE*)CNBuffer; BYTE* dst = (BYTE*)compressedBuffer;
+        ZSTD_CCtx* const cctx = ZSTD_createCCtx();
+        const BYTE* src = (BYTE*)CNBuffer; BYTE* dst = (BYTE*)compressedBuffer;
         size_t srcSize = 321656; size_t dstCapacity = ZSTD_compressBound(srcSize);
 
         /* This is the number of bytes to stream before ending. This value
@@ -501,20 +501,21 @@ static int basicUnitTests(U32 const seed, double compressibility)
         const size_t streamCompressThreshold = 161792;
         const size_t streamCompressDelta = 1024;
 
-        /* The first 1/3 of the buffer is compressable and the last 2/3 is
-         * uncompressable. This is an approximation of the type of data
+        /* The first 1/3 of the buffer is compressible and the last 2/3 is
+         * uncompressible. This is an approximation of the type of data
          * the fuzzer generated to catch this bug. Streams like this were making
          * zstd generate noCompress superblocks (which are larger than the src
          * they come from). Do this enough times, and we'll run out of room
          * and throw a dstSize_tooSmall error. */
 
-        const size_t compressablePartSize = srcSize/3;
-        const size_t uncompressablePartSize = srcSize-compressablePartSize;
-        RDG_genBuffer(CNBuffer, compressablePartSize, 0.5, 0.5, seed);
-        RDG_genBuffer((BYTE*)CNBuffer+compressablePartSize, uncompressablePartSize, 0, 0, seed);
+        const size_t compressiblePartSize = srcSize/3;
+        const size_t uncompressiblePartSize = srcSize-compressiblePartSize;
+        RDG_genBuffer(CNBuffer, compressiblePartSize, 0.5, 0.5, seed);
+        RDG_genBuffer((BYTE*)CNBuffer+compressiblePartSize, uncompressiblePartSize, 0, 0, seed);
 
         /* Setting target block size so that superblock is used */
 
+        assert(cctx != NULL);
         ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetCBlockSize, 81);
 
         { size_t read;