From 56415efc76b8407df39e872b2f5bf65c6badf507 Mon Sep 17 00:00:00 2001 From: Bimba Shrestha Date: Tue, 17 Dec 2019 17:16:51 -0800 Subject: [PATCH] Constifying, malloc check and naming nit --- lib/compress/zstd_compress.c | 2 +- tests/fuzzer.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 338f8dd5..a674cea4 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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); diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 7880c5d4..337455d9 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -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;