From f98c69d77cd9b1dde60df2de05613006842d4896 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 26 Sep 2018 14:24:28 -0700 Subject: [PATCH 1/9] fix : huge (>4GB) stream of blocks experimental function ZSTD_compressBlock() is designed for very small data in mind, for situation where saving the ~12 bytes of frame header can actually make a difference. Some systems though may have to deal with small and large data entangled. If it's larger than a block (> 128KB), compressBlock() cannot compress them in one round. That's why it's possible to compress in multiple rounds. This is a chain of compressed blocks. Some users push this capability to the limit, encoding gigantic chain of blocks. On crossing the 4GB limit, some internal overflow occurs. This fix moves the overflow correction mechanism higher in the call chain, so that it's applied also to gigantic chains of blocks. Added a test case in fuzzer.c, which crashes before the fix, and pass now. --- lib/compress/zstd_compress.c | 27 ++++++++++++++------------- lib/compress/zstd_fast.c | 1 + tests/fuzzer.c | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 98e9917ab..714f2a7e4 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2454,19 +2454,6 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */ if (remaining < blockSize) blockSize = remaining; - if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) { - U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); - U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip); - ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); - - ZSTD_reduceIndex(cctx, correction); - if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; - else ms->nextToUpdate -= correction; - ms->loadedDictEnd = 0; - ms->dictMatchState = NULL; - } ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit; @@ -2603,6 +2590,20 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, if (cctx->appliedParams.ldmParams.enableLdm) ZSTD_window_update(&cctx->ldmState.window, src, srcSize); + if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) { + U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); + U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src); + ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); + + ZSTD_reduceIndex(cctx, correction); + if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; + else ms->nextToUpdate -= correction; + ms->loadedDictEnd = 0; + ms->dictMatchState = NULL; + } + DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (U32)cctx->blockSize); { size_t const cSize = frame ? ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : diff --git a/lib/compress/zstd_fast.c b/lib/compress/zstd_fast.c index 7d7efb465..8d2c8452a 100644 --- a/lib/compress/zstd_fast.c +++ b/lib/compress/zstd_fast.c @@ -172,6 +172,7 @@ size_t ZSTD_compressBlock_fast_generic( if (ip <= ilimit) { /* Fill Table */ + assert(base+current+2 > istart); /* check base overflow */ hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2; /* here because current+2 could be > iend-8 */ hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base); diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 7191ffcbb..24e00e803 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1291,6 +1291,20 @@ static int basicUnitTests(U32 seed, double compressibility) if (r != blockSize) goto _output_error; } DISPLAYLEVEL(3, "OK \n"); + /* very long stream of block compression */ + DISPLAYLEVEL(3, "test%3i : Huge block streaming compression test : ", testNb++); + CHECK( ZSTD_compressBegin(cctx, -99) ); /* we just want to quickly overflow internal U32 index */ + CHECK( ZSTD_getBlockSize(cctx) >= blockSize); + { U64 const toCompress = 5000000000ULL; /* > 4 GB */ + U64 compressed = 0; + while (compressed < toCompress) { + size_t const blockCSize = ZSTD_compressBlock(cctx, compressedBuffer, ZSTD_compressBound(blockSize), CNBuffer, blockSize); + if (ZSTD_isError(cSize)) goto _output_error; + compressed += blockCSize; + } + } + DISPLAYLEVEL(3, "OK \n"); + /* dictionary block compression */ DISPLAYLEVEL(3, "test%3i : Dictionary Block compression test : ", testNb++); CHECK( ZSTD_compressBegin_usingDict(cctx, CNBuffer, dictSize, 5) ); From 0e2dbac18a2ba6ee073120f09b8b90f323bbfbc1 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 26 Sep 2018 15:35:38 -0700 Subject: [PATCH 2/9] changed overflow correction place keep one in compress_frameChunk(), so that it's tested at every loop in case some user simply some large mulit-GB input in a single invocation. Add one in ZSTD_compressBlock(), since compressBlock() explicitly skips frameChunk(). --- lib/compress/zstd_compress.c | 47 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 714f2a7e4..90c15291f 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2333,6 +2333,7 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, ZSTD_matchState_t* const ms = &zc->blockState.matchState; DEBUGLOG(5, "ZSTD_compressBlock_internal (dstCapacity=%zu, dictLimit=%u, nextToUpdate=%u)", dstCapacity, ms->window.dictLimit, ms->nextToUpdate); + assert(srcSize <= ZSTD_BLOCKSIZE_MAX); if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) { ZSTD_ldm_skipSequences(&zc->externSeqStore, srcSize, zc->appliedParams.cParams.searchLength); @@ -2454,7 +2455,19 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, return ERROR(dstSize_tooSmall); /* not enough space to store compressed block */ if (remaining < blockSize) blockSize = remaining; - ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); + if (ZSTD_window_needOverflowCorrection(ms->window, ip + blockSize)) { + U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); + U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, maxDist, ip); + ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); + ZSTD_reduceIndex(cctx, correction); + if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; + else ms->nextToUpdate -= correction; + ms->loadedDictEnd = 0; + ms->dictMatchState = NULL; + } + ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit; { size_t cSize = ZSTD_compressBlock_internal(cctx, @@ -2566,7 +2579,7 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, const void* src, size_t srcSize, U32 frame, U32 lastFrameChunk) { - ZSTD_matchState_t* ms = &cctx->blockState.matchState; + ZSTD_matchState_t* const ms = &cctx->blockState.matchState; size_t fhSize = 0; DEBUGLOG(5, "ZSTD_compressContinue_internal, stage: %u, srcSize: %u", @@ -2590,20 +2603,6 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, if (cctx->appliedParams.ldmParams.enableLdm) ZSTD_window_update(&cctx->ldmState.window, src, srcSize); - if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) { - U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); - U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src); - ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); - - ZSTD_reduceIndex(cctx, correction); - if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; - else ms->nextToUpdate -= correction; - ms->loadedDictEnd = 0; - ms->dictMatchState = NULL; - } - DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (U32)cctx->blockSize); { size_t const cSize = frame ? ZSTD_compress_frameChunk (cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : @@ -2642,8 +2641,24 @@ size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx) size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { + ZSTD_matchState_t* const ms = &cctx->blockState.matchState; size_t const blockSizeMax = ZSTD_getBlockSize(cctx); if (srcSize > blockSizeMax) return ERROR(srcSize_wrong); + + if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) { + U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); + U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src); + ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); + + ZSTD_reduceIndex(cctx, correction); + if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; + else ms->nextToUpdate -= correction; + ms->loadedDictEnd = 0; + ms->dictMatchState = NULL; + } + return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */); } From 404a7bfed0cad56ef9700fb746c15e85e5544467 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 26 Sep 2018 18:06:53 -0700 Subject: [PATCH 3/9] moved again overflow correction cannot work from within ZSTD_compressBlock() --- lib/compress/zstd_compress.c | 38 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 90c15291f..a969bd31c 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2461,13 +2461,13 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); - ZSTD_reduceIndex(cctx, correction); + ZSTD_reduceIndex(cctx, correction); if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; else ms->nextToUpdate -= correction; ms->loadedDictEnd = 0; ms->dictMatchState = NULL; } - ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); + ZSTD_window_enforceMaxDist(&ms->window, ip + blockSize, maxDist, &ms->loadedDictEnd, &ms->dictMatchState); if (ms->nextToUpdate < ms->window.lowLimit) ms->nextToUpdate = ms->window.lowLimit; { size_t cSize = ZSTD_compressBlock_internal(cctx, @@ -2600,8 +2600,25 @@ static size_t ZSTD_compressContinue_internal (ZSTD_CCtx* cctx, if (!ZSTD_window_update(&ms->window, src, srcSize)) { ms->nextToUpdate = ms->window.dictLimit; } - if (cctx->appliedParams.ldmParams.enableLdm) + if (cctx->appliedParams.ldmParams.enableLdm) { ZSTD_window_update(&cctx->ldmState.window, src, srcSize); + } + + if (!frame) { + /* overflow check and correction for block mode */ + if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) { + U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); + U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src); + ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); + ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); + ZSTD_reduceIndex(cctx, correction); + if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; + else ms->nextToUpdate -= correction; + ms->loadedDictEnd = 0; + ms->dictMatchState = NULL; + } + } DEBUGLOG(5, "ZSTD_compressContinue_internal (blockSize=%u)", (U32)cctx->blockSize); { size_t const cSize = frame ? @@ -2641,24 +2658,9 @@ size_t ZSTD_getBlockSize(const ZSTD_CCtx* cctx) size_t ZSTD_compressBlock(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { - ZSTD_matchState_t* const ms = &cctx->blockState.matchState; size_t const blockSizeMax = ZSTD_getBlockSize(cctx); if (srcSize > blockSizeMax) return ERROR(srcSize_wrong); - if (ZSTD_window_needOverflowCorrection(ms->window, (const char*)src + srcSize)) { - U32 const cycleLog = ZSTD_cycleLog(cctx->appliedParams.cParams.chainLog, cctx->appliedParams.cParams.strategy); - U32 const correction = ZSTD_window_correctOverflow(&ms->window, cycleLog, 1 << cctx->appliedParams.cParams.windowLog, src); - ZSTD_STATIC_ASSERT(ZSTD_CHAINLOG_MAX <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX_32 <= 30); - ZSTD_STATIC_ASSERT(ZSTD_WINDOWLOG_MAX <= 31); - - ZSTD_reduceIndex(cctx, correction); - if (ms->nextToUpdate < correction) ms->nextToUpdate = 0; - else ms->nextToUpdate -= correction; - ms->loadedDictEnd = 0; - ms->dictMatchState = NULL; - } - return ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0 /* frame mode */, 0 /* last chunk */); } From f2d6db45cd28457fa08467416e8535985f062859 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 27 Sep 2018 15:13:43 -0700 Subject: [PATCH 4/9] [zstd] Add -Wmissing-prototypes --- lib/Makefile | 2 +- lib/compress/fse_compress.c | 13 ------------- lib/compress/huf_compress.c | 2 +- lib/compress/zstd_compress.c | 25 ++++++++----------------- lib/compress/zstd_lazy.c | 2 +- lib/compress/zstd_opt.c | 2 +- lib/compress/zstdmt_compress.c | 2 +- lib/decompress/zstd_decompress.c | 6 ++++++ lib/dictBuilder/zdict.c | 13 +++++++++---- lib/legacy/zstd_v01.c | 6 +++--- lib/legacy/zstd_v04.c | 5 ----- lib/legacy/zstd_v05.c | 9 +++++---- lib/legacy/zstd_v06.c | 17 ++++++++--------- lib/legacy/zstd_v07.c | 18 +++++++++--------- programs/Makefile | 2 +- programs/datagen.c | 3 ++- programs/dibio.c | 4 ---- programs/fileio.c | 2 +- tests/Makefile | 2 +- tests/fullbench.c | 22 +++++++++++----------- tests/fuzzer.c | 2 ++ tests/paramgrill.c | 6 +++--- tests/zstreamtest.c | 4 ++-- 23 files changed, 76 insertions(+), 93 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index a161809cb..3502464b8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -27,7 +27,7 @@ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \ -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ - -Wredundant-decls + -Wredundant-decls -Wmissing-prototypes CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) FLAGS = $(CPPFLAGS) $(CFLAGS) diff --git a/lib/compress/fse_compress.c b/lib/compress/fse_compress.c index 4075db217..4408f0ed5 100644 --- a/lib/compress/fse_compress.c +++ b/lib/compress/fse_compress.c @@ -321,19 +321,6 @@ size_t FSE_writeNCount (void* buffer, size_t bufferSize, /*-************************************************************** * FSE Compression Code ****************************************************************/ -/*! FSE_sizeof_CTable() : - FSE_CTable is a variable size structure which contains : - `U16 tableLog;` - `U16 maxSymbolValue;` - `U16 nextStateNumber[1 << tableLog];` // This size is variable - `FSE_symbolCompressionTransform symbolTT[maxSymbolValue+1];` // This size is variable -Allocation is manual (C standard does not support variable-size structures). -*/ -size_t FSE_sizeof_CTable (unsigned maxSymbolValue, unsigned tableLog) -{ - if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); - return FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); -} FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog) { diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index 9cdaa5d79..4c40572f2 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -82,7 +82,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS * Note : all elements within weightTable are supposed to be <= HUF_TABLELOG_MAX. */ #define MAX_FSE_TABLELOG_FOR_HUFF_HEADER 6 -size_t HUF_compressWeights (void* dst, size_t dstSize, const void* weightTable, size_t wtSize) +static size_t HUF_compressWeights (void* dst, size_t dstSize, const void* weightTable, size_t wtSize) { BYTE* const ostart = (BYTE*) dst; BYTE* op = ostart; diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 18c7cc14b..fcdf93f57 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -1531,15 +1531,6 @@ static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue) /* See doc/zstd_compression_format.md for detailed format description */ -size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize) -{ - if (srcSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); - memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize); - MEM_writeLE24(dst, (U32)(srcSize << 2) + (U32)bt_raw); - return ZSTD_blockHeaderSize+srcSize; -} - - static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize) { BYTE* const ostart = (BYTE* const)dst; @@ -2091,7 +2082,7 @@ ZSTD_encodeSequences_bmi2( #endif -size_t ZSTD_encodeSequences( +static size_t ZSTD_encodeSequences( void* dst, size_t dstCapacity, FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable, FSE_CTable const* CTable_OffsetBits, BYTE const* ofCodeTable, @@ -2883,13 +2874,13 @@ ZSTD_compress_insertDictionary(ZSTD_compressedBlockState_t* bs, /*! ZSTD_compressBegin_internal() : * @return : 0, or an error code */ -size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, - const void* dict, size_t dictSize, - ZSTD_dictContentType_e dictContentType, - ZSTD_dictTableLoadMethod_e dtlm, - const ZSTD_CDict* cdict, - ZSTD_CCtx_params params, U64 pledgedSrcSize, - ZSTD_buffered_policy_e zbuff) +static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx, + const void* dict, size_t dictSize, + ZSTD_dictContentType_e dictContentType, + ZSTD_dictTableLoadMethod_e dtlm, + const ZSTD_CDict* cdict, + ZSTD_CCtx_params params, U64 pledgedSrcSize, + ZSTD_buffered_policy_e zbuff) { DEBUGLOG(4, "ZSTD_compressBegin_internal: wlog=%u", params.cParams.windowLog); /* params are supposed to be fully validated at this point */ diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index bfe944928..f17fced15 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -16,7 +16,7 @@ * Binary Tree search ***************************************/ -void ZSTD_updateDUBT( +static void ZSTD_updateDUBT( ZSTD_matchState_t* ms, ZSTD_compressionParameters const* cParams, const BYTE* ip, const BYTE* iend, U32 mls) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index c4b9bb13b..694deec78 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -741,7 +741,7 @@ typedef struct repcodes_s { U32 rep[3]; } repcodes_t; -repcodes_t ZSTD_updateRep(U32 const rep[3], U32 const offset, U32 const ll0) +static repcodes_t ZSTD_updateRep(U32 const rep[3], U32 const offset, U32 const ll0) { repcodes_t newReps; if (offset >= ZSTD_REP_NUM) { /* full offset */ diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 6b9c24b56..f4aba1d2c 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -640,7 +640,7 @@ typedef struct { } /* ZSTDMT_compressionJob() is a POOL_function type */ -void ZSTDMT_compressionJob(void* jobDescription) +static void ZSTDMT_compressionJob(void* jobDescription) { ZSTDMT_jobDescription* const job = (ZSTDMT_jobDescription*)jobDescription; ZSTD_CCtx_params jobParams = job->params; /* do not modify job->params ! copy it, modify the copy */ diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 1382c9c7f..e7e91b180 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -568,6 +568,9 @@ static size_t ZSTD_setRleBlock(void* dst, size_t dstCapacity, return regenSize; } +/* Hidden declaration for fullbench */ +size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, + const void* src, size_t srcSize); /*! ZSTD_decodeLiteralsBlock() : * @return : nb of bytes read from src (< srcSize ) * note : symbol not declared but exposed for fullbench */ @@ -972,6 +975,9 @@ static const U32 ML_base[MaxML+1] = { 67, 83, 99, 0x83, 0x103, 0x203, 0x403, 0x803, 0x1003, 0x2003, 0x4003, 0x8003, 0x10003 }; +/* Hidden delcaration for fullbench */ +size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr, + const void* src, size_t srcSize); size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr, const void* src, size_t srcSize) diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index eb1a5b669..2964b69ff 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -910,9 +910,10 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity, } -size_t ZDICT_addEntropyTablesFromBuffer_advanced(void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity, - const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, - ZDICT_params_t params) +static size_t ZDICT_addEntropyTablesFromBuffer_advanced( + void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity, + const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, + ZDICT_params_t params) { int const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel; U32 const notificationLevel = params.notificationLevel; @@ -943,7 +944,11 @@ size_t ZDICT_addEntropyTablesFromBuffer_advanced(void* dictBuffer, size_t dictCo return MIN(dictBufferCapacity, hSize+dictContentSize); } - +/* Hidden declaration for dbio.c */ +size_t ZDICT_trainFromBuffer_unsafe_legacy( + void* dictBuffer, size_t maxDictSize, + const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, + ZDICT_legacy_params_t params); /*! ZDICT_trainFromBuffer_unsafe_legacy() : * Warning : `samplesBuffer` must be followed by noisy guard band. * @return : size of dictionary, or an error code which can be tested with ZDICT_isError() diff --git a/lib/legacy/zstd_v01.c b/lib/legacy/zstd_v01.c index ae1cb2ce5..6303e1cfc 100644 --- a/lib/legacy/zstd_v01.c +++ b/lib/legacy/zstd_v01.c @@ -1458,7 +1458,7 @@ unsigned ZSTDv01_isError(size_t code) { return ERR_isError(code); } * Decompression code **************************************************************/ -size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) +static size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) { const BYTE* const in = (const BYTE* const)src; BYTE headerFlags; @@ -1511,7 +1511,7 @@ static size_t ZSTD_decompressLiterals(void* ctx, } -size_t ZSTDv01_decodeLiteralsBlock(void* ctx, +static size_t ZSTDv01_decodeLiteralsBlock(void* ctx, void* dst, size_t maxDstSize, const BYTE** litStart, size_t* litSize, const void* src, size_t srcSize) @@ -1563,7 +1563,7 @@ size_t ZSTDv01_decodeLiteralsBlock(void* ctx, } -size_t ZSTDv01_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr, +static size_t ZSTDv01_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr, FSE_DTable* DTableLL, FSE_DTable* DTableML, FSE_DTable* DTableOffb, const void* src, size_t srcSize) { diff --git a/lib/legacy/zstd_v04.c b/lib/legacy/zstd_v04.c index 15000db6d..e852bb911 100644 --- a/lib/legacy/zstd_v04.c +++ b/lib/legacy/zstd_v04.c @@ -3622,8 +3622,3 @@ size_t ZBUFFv04_decompressContinue(ZBUFFv04_DCtx* dctx, void* dst, size_t* maxDs ZSTD_DCtx* ZSTDv04_createDCtx(void) { return ZSTD_createDCtx(); } size_t ZSTDv04_freeDCtx(ZSTD_DCtx* dctx) { return ZSTD_freeDCtx(dctx); } - -size_t ZSTDv04_getFrameParams(ZSTD_parameters* params, const void* src, size_t srcSize) -{ - return ZSTD_getFrameParams(params, src, srcSize); -} diff --git a/lib/legacy/zstd_v05.c b/lib/legacy/zstd_v05.c index 65f07a3b5..6f4dc72b7 100644 --- a/lib/legacy/zstd_v05.c +++ b/lib/legacy/zstd_v05.c @@ -2659,6 +2659,7 @@ struct ZSTDv05_DCtx_s BYTE headerBuffer[ZSTDv05_frameHeaderSize_max]; }; /* typedef'd to ZSTDv05_DCtx within "zstd_static.h" */ +size_t ZSTDv05_sizeofDCtx (void); /* Hidden declaration */ size_t ZSTDv05_sizeofDCtx (void) { return sizeof(ZSTDv05_DCtx); } size_t ZSTDv05_decompressBegin(ZSTDv05_DCtx* dctx) @@ -2823,7 +2824,7 @@ static size_t ZSTDv05_decodeFrameHeader_Part2(ZSTDv05_DCtx* zc, const void* src, } -size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) +static size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) { const BYTE* const in = (const BYTE* const)src; BYTE headerFlags; @@ -2855,8 +2856,8 @@ static size_t ZSTDv05_copyRawBlock(void* dst, size_t maxDstSize, const void* src /*! ZSTDv05_decodeLiteralsBlock() : @return : nb of bytes read from src (< srcSize ) */ -size_t ZSTDv05_decodeLiteralsBlock(ZSTDv05_DCtx* dctx, - const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ +static size_t ZSTDv05_decodeLiteralsBlock(ZSTDv05_DCtx* dctx, + const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ { const BYTE* const istart = (const BYTE*) src; @@ -2990,7 +2991,7 @@ size_t ZSTDv05_decodeLiteralsBlock(ZSTDv05_DCtx* dctx, } -size_t ZSTDv05_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr, +static size_t ZSTDv05_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr, FSEv05_DTable* DTableLL, FSEv05_DTable* DTableML, FSEv05_DTable* DTableOffb, const void* src, size_t srcSize, U32 flagStaticTable) { diff --git a/lib/legacy/zstd_v06.c b/lib/legacy/zstd_v06.c index ca982c35e..60d8d6fd9 100644 --- a/lib/legacy/zstd_v06.c +++ b/lib/legacy/zstd_v06.c @@ -1250,9 +1250,7 @@ const char* FSEv06_getErrorName(size_t code) { return ERR_getErrorName(code); } /* ************************************************************** * HUF Error Management ****************************************************************/ -unsigned HUFv06_isError(size_t code) { return ERR_isError(code); } - -const char* HUFv06_getErrorName(size_t code) { return ERR_getErrorName(code); } +static unsigned HUFv06_isError(size_t code) { return ERR_isError(code); } /*-************************************************************** @@ -2823,7 +2821,8 @@ struct ZSTDv06_DCtx_s BYTE headerBuffer[ZSTDv06_FRAMEHEADERSIZE_MAX]; }; /* typedef'd to ZSTDv06_DCtx within "zstd_static.h" */ -size_t ZSTDv06_sizeofDCtx (void) { return sizeof(ZSTDv06_DCtx); } /* non published interface */ +size_t ZSTDv06_sizeofDCtx (void); /* Hidden declaration */ +size_t ZSTDv06_sizeofDCtx (void) { return sizeof(ZSTDv06_DCtx); } size_t ZSTDv06_decompressBegin(ZSTDv06_DCtx* dctx) { @@ -3022,7 +3021,7 @@ typedef struct /*! ZSTDv06_getcBlockSize() : * Provides the size of compressed block from block header `src` */ -size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) +static size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) { const BYTE* const in = (const BYTE* const)src; U32 cSize; @@ -3050,7 +3049,7 @@ static size_t ZSTDv06_copyRawBlock(void* dst, size_t dstCapacity, const void* sr /*! ZSTDv06_decodeLiteralsBlock() : @return : nb of bytes read from src (< srcSize ) */ -size_t ZSTDv06_decodeLiteralsBlock(ZSTDv06_DCtx* dctx, +static size_t ZSTDv06_decodeLiteralsBlock(ZSTDv06_DCtx* dctx, const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ { const BYTE* const istart = (const BYTE*) src; @@ -3184,7 +3183,7 @@ size_t ZSTDv06_decodeLiteralsBlock(ZSTDv06_DCtx* dctx, @return : nb bytes read from src, or an error code if it fails, testable with ZSTDv06_isError() */ -size_t ZSTDv06_buildSeqTable(FSEv06_DTable* DTable, U32 type, U32 max, U32 maxLog, +static size_t ZSTDv06_buildSeqTable(FSEv06_DTable* DTable, U32 type, U32 max, U32 maxLog, const void* src, size_t srcSize, const S16* defaultNorm, U32 defaultLog, U32 flagRepeatTable) { @@ -3214,7 +3213,7 @@ size_t ZSTDv06_buildSeqTable(FSEv06_DTable* DTable, U32 type, U32 max, U32 maxLo } -size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr, +static size_t ZSTDv06_decodeSeqHeaders(int* nbSeqPtr, FSEv06_DTable* DTableLL, FSEv06_DTable* DTableML, FSEv06_DTable* DTableOffb, U32 flagRepeatTable, const void* src, size_t srcSize) { @@ -3359,7 +3358,7 @@ static void ZSTDv06_decodeSequence(seq_t* seq, seqState_t* seqState) } -size_t ZSTDv06_execSequence(BYTE* op, +static size_t ZSTDv06_execSequence(BYTE* op, BYTE* const oend, seq_t sequence, const BYTE** litPtr, const BYTE* const litLimit, const BYTE* const base, const BYTE* const vBase, const BYTE* const dictEnd) diff --git a/lib/legacy/zstd_v07.c b/lib/legacy/zstd_v07.c index 9f95f62ad..c7bb7a529 100644 --- a/lib/legacy/zstd_v07.c +++ b/lib/legacy/zstd_v07.c @@ -2628,7 +2628,7 @@ const char* ZBUFFv07_getErrorName(size_t errorCode) { return ERR_getErrorName(er -void* ZSTDv07_defaultAllocFunction(void* opaque, size_t size) +static void* ZSTDv07_defaultAllocFunction(void* opaque, size_t size) { void* address = malloc(size); (void)opaque; @@ -2636,7 +2636,7 @@ void* ZSTDv07_defaultAllocFunction(void* opaque, size_t size) return address; } -void ZSTDv07_defaultFreeFunction(void* opaque, void* address) +static void ZSTDv07_defaultFreeFunction(void* opaque, void* address) { (void)opaque; /* if (address) printf("free %p opaque=%p \n", address, opaque); */ @@ -3250,7 +3250,7 @@ typedef struct /*! ZSTDv07_getcBlockSize() : * Provides the size of compressed block from block header `src` */ -size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) +static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr) { const BYTE* const in = (const BYTE* const)src; U32 cSize; @@ -3277,7 +3277,7 @@ static size_t ZSTDv07_copyRawBlock(void* dst, size_t dstCapacity, const void* sr /*! ZSTDv07_decodeLiteralsBlock() : @return : nb of bytes read from src (< srcSize ) */ -size_t ZSTDv07_decodeLiteralsBlock(ZSTDv07_DCtx* dctx, +static size_t ZSTDv07_decodeLiteralsBlock(ZSTDv07_DCtx* dctx, const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ { const BYTE* const istart = (const BYTE*) src; @@ -3411,7 +3411,7 @@ size_t ZSTDv07_decodeLiteralsBlock(ZSTDv07_DCtx* dctx, @return : nb bytes read from src, or an error code if it fails, testable with ZSTDv07_isError() */ -size_t ZSTDv07_buildSeqTable(FSEv07_DTable* DTable, U32 type, U32 max, U32 maxLog, +static size_t ZSTDv07_buildSeqTable(FSEv07_DTable* DTable, U32 type, U32 max, U32 maxLog, const void* src, size_t srcSize, const S16* defaultNorm, U32 defaultLog, U32 flagRepeatTable) { @@ -3441,7 +3441,7 @@ size_t ZSTDv07_buildSeqTable(FSEv07_DTable* DTable, U32 type, U32 max, U32 maxLo } -size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr, +static size_t ZSTDv07_decodeSeqHeaders(int* nbSeqPtr, FSEv07_DTable* DTableLL, FSEv07_DTable* DTableML, FSEv07_DTable* DTableOffb, U32 flagRepeatTable, const void* src, size_t srcSize) { @@ -3773,7 +3773,7 @@ ZSTDLIBv07_API size_t ZSTDv07_insertBlock(ZSTDv07_DCtx* dctx, const void* blockS } -size_t ZSTDv07_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t length) +static size_t ZSTDv07_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t length) { if (length > dstCapacity) return ERROR(dstSize_tooSmall); memset(dst, byte, length); @@ -3853,7 +3853,7 @@ static size_t ZSTDv07_decompressFrame(ZSTDv07_DCtx* dctx, * It avoids reloading the dictionary each time. * `preparedDCtx` must have been properly initialized using ZSTDv07_decompressBegin_usingDict(). * Requires 2 contexts : 1 for reference (preparedDCtx), which will not be modified, and 1 to run the decompression operation (dctx) */ -size_t ZSTDv07_decompress_usingPreparedDCtx(ZSTDv07_DCtx* dctx, const ZSTDv07_DCtx* refDCtx, +static size_t ZSTDv07_decompress_usingPreparedDCtx(ZSTDv07_DCtx* dctx, const ZSTDv07_DCtx* refDCtx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) { @@ -4148,7 +4148,7 @@ struct ZSTDv07_DDict_s { ZSTDv07_DCtx* refContext; }; /* typedef'd tp ZSTDv07_CDict within zstd.h */ -ZSTDv07_DDict* ZSTDv07_createDDict_advanced(const void* dict, size_t dictSize, ZSTDv07_customMem customMem) +static ZSTDv07_DDict* ZSTDv07_createDDict_advanced(const void* dict, size_t dictSize, ZSTDv07_customMem customMem) { if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem; diff --git a/programs/Makefile b/programs/Makefile index 7dc65118b..5948cf158 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -48,7 +48,7 @@ DEBUGFLAGS+=-Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \ -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ - -Wredundant-decls + -Wredundant-decls -Wmissing-prototypes CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) diff --git a/programs/datagen.c b/programs/datagen.c index a489d6af0..c83836584 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -13,6 +13,7 @@ /*-************************************ * Dependencies **************************************/ +#include "datagen.h" #include "platform.h" /* SET_BINARY_MODE */ #include /* malloc, free */ #include /* FILE, fwrite, fprintf */ @@ -91,7 +92,7 @@ static U32 RDG_randLength(unsigned* seedPtr) return (RDG_rand(seedPtr) & 0x1FF) + 0xF; } -void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double matchProba, const BYTE* ldt, unsigned* seedPtr) +static void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double matchProba, const BYTE* ldt, unsigned* seedPtr) { BYTE* const buffPtr = (BYTE*)buffer; U32 const matchProba32 = (U32)(32768 * matchProba); diff --git a/programs/dibio.c b/programs/dibio.c index 4b68be6c9..d3fd8cc05 100644 --- a/programs/dibio.c +++ b/programs/dibio.c @@ -84,10 +84,6 @@ static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; /* ******************************************************** * Helper functions **********************************************************/ -unsigned DiB_isError(size_t errorCode) { return ERR_isError(errorCode); } - -const char* DiB_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); } - #undef MIN #define MIN(a,b) ((a) < (b) ? (a) : (b)) diff --git a/programs/fileio.c b/programs/fileio.c index 53f72aa72..1b04f2ea0 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1422,7 +1422,7 @@ static void FIO_zstdErrorHelp(dRess_t* ress, size_t err, char const* srcFileName * @return : size of decoded zstd frame, or an error code */ #define FIO_ERROR_FRAME_DECODING ((unsigned long long)(-2)) -unsigned long long FIO_decompressZstdFrame(dRess_t* ress, +static unsigned long long FIO_decompressZstdFrame(dRess_t* ress, FILE* finput, const char* srcFileName, U64 alreadyDecoded) diff --git a/tests/Makefile b/tests/Makefile index d0d798fc3..50c1a6156 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -35,7 +35,7 @@ CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ -Wstrict-prototypes -Wundef -Wformat-security \ -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ - -Wredundant-decls + -Wredundant-decls -Wmissing-prototypes CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) diff --git a/tests/fullbench.c b/tests/fullbench.c index fd4815c91..b05f1537c 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -127,14 +127,14 @@ static ZSTD_DCtx* g_zdc = NULL; #ifndef ZSTD_DLL_IMPORT extern size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* ctx, const void* src, size_t srcSize); -size_t local_ZSTD_decodeLiteralsBlock(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2) +static size_t local_ZSTD_decodeLiteralsBlock(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2) { (void)src; (void)srcSize; (void)dst; (void)dstSize; return ZSTD_decodeLiteralsBlock((ZSTD_DCtx*)g_zdc, buff2, g_cSize); } extern size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeq, const void* src, size_t srcSize); -size_t local_ZSTD_decodeSeqHeaders(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2) +static size_t local_ZSTD_decodeSeqHeaders(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2) { int nbSeq; (void)src; (void)srcSize; (void)dst; (void)dstSize; @@ -263,9 +263,9 @@ local_ZSTD_decompressStream(const void* src, size_t srcSize, } #ifndef ZSTD_DLL_IMPORT -size_t local_ZSTD_compressContinue(const void* src, size_t srcSize, - void* dst, size_t dstCapacity, - void* buff2) +static size_t local_ZSTD_compressContinue(const void* src, size_t srcSize, + void* dst, size_t dstCapacity, + void* buff2) { ZSTD_parameters p; ZSTD_frameParameters f = { 1 /* contentSizeHeader*/, 0, 0 }; @@ -276,9 +276,9 @@ size_t local_ZSTD_compressContinue(const void* src, size_t srcSize, } #define FIRST_BLOCK_SIZE 8 -size_t local_ZSTD_compressContinue_extDict(const void* src, size_t srcSize, - void* dst, size_t dstCapacity, - void* buff2) +static size_t local_ZSTD_compressContinue_extDict(const void* src, size_t srcSize, + void* dst, size_t dstCapacity, + void* buff2) { BYTE firstBlockBuf[FIRST_BLOCK_SIZE]; @@ -305,9 +305,9 @@ size_t local_ZSTD_compressContinue_extDict(const void* src, size_t srcSize, srcSize - FIRST_BLOCK_SIZE); } -size_t local_ZSTD_decompressContinue(const void* src, size_t srcSize, - void* dst, size_t dstCapacity, - void* buff2) +static size_t local_ZSTD_decompressContinue(const void* src, size_t srcSize, + void* dst, size_t dstCapacity, + void* buff2) { size_t regeneratedSize = 0; const BYTE* ip = (const BYTE*)buff2; diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 24e00e803..5616285b9 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -72,6 +72,8 @@ static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER; *********************************************************/ #undef MIN #undef MAX +/* Declaring the function is it isn't unused */ +void FUZ_bug976(void); void FUZ_bug976(void) { /* these constants shall not depend on MIN() macro */ assert(ZSTD_HASHLOG_MAX < 31); diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 68e1fbc4d..466a156d3 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -374,7 +374,7 @@ static U32 FUZ_rotl32(U32 x, U32 r) return ((x << r) | (x >> (32 - r))); } -U32 FUZ_rand(U32* src) +static U32 FUZ_rand(U32* src) { const U32 prime1 = 2654435761U; const U32 prime2 = 2246822519U; @@ -1937,8 +1937,8 @@ static int benchSample(double compressibility, int cLevel) /* benchFiles() : * note: while this function takes a table of filenames, * in practice, only the first filename will be used */ -int benchFiles(const char** fileNamesTable, int nbFiles, - const char* dictFileName, int cLevel) +static int benchFiles(const char** fileNamesTable, int nbFiles, + const char* dictFileName, int cLevel) { buffers_t buf; contexts_t ctx; diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 96136a625..4d32c19ea 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -84,7 +84,7 @@ static U64 g_clockTime = 0; @return : a 27 bits random value, from a 32-bits `seed`. `seed` is also modified */ #define FUZ_rotl32(x,r) ((x << r) | (x >> (32 - r))) -unsigned int FUZ_rand(unsigned int* seedPtr) +static unsigned int FUZ_rand(unsigned int* seedPtr) { static const U32 prime2 = 2246822519U; U32 rand32 = *seedPtr; @@ -2040,7 +2040,7 @@ _output_error: /*-******************************************************* * Command line *********************************************************/ -int FUZ_usage(const char* programName) +static int FUZ_usage(const char* programName) { DISPLAY( "Usage :\n"); DISPLAY( " %s [args]\n", programName); From 109bd374741860753f8d6929f53264f7fc4b192e Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 27 Sep 2018 15:22:34 -0700 Subject: [PATCH 5/9] Include stddef.h for size_t --- lib/common/xxhash.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/common/xxhash.c b/lib/common/xxhash.c index 9d9c0e963..532b81619 100644 --- a/lib/common/xxhash.c +++ b/lib/common/xxhash.c @@ -98,6 +98,7 @@ /* Modify the local functions below should you wish to use some other memory routines */ /* for malloc(), free() */ #include +#include /* size_t */ static void* XXH_malloc(size_t s) { return malloc(s); } static void XXH_free (void* p) { free(p); } /* for memcpy() */ From aec1a3ec58a11a7dcff8d630a38f9c25db549a84 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 27 Sep 2018 15:23:20 -0700 Subject: [PATCH 6/9] Change byte to value to avoid a GRUB typedef --- lib/decompress/zstd_decompress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index e7e91b180..711b5b6d7 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1788,10 +1788,10 @@ ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, siz } -static size_t ZSTD_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t length) +static size_t ZSTD_generateNxBytes(void* dst, size_t dstCapacity, BYTE value, size_t length) { if (length > dstCapacity) return ERROR(dstSize_tooSmall); - memset(dst, byte, length); + memset(dst, value, length); return length; } From a180ea07c4d945bf9400a70494bf458841a44437 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 27 Sep 2018 16:06:02 -0700 Subject: [PATCH 7/9] Restore ZSTD_noCompressBlock() for clarity --- lib/compress/zstd_compress.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index fcdf93f57..3eb5ceb21 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -1531,6 +1531,15 @@ static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue) /* See doc/zstd_compression_format.md for detailed format description */ +static size_t ZSTD_noCompressBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize, U32 lastBlock) +{ + U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(srcSize << 3); + if (srcSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); + MEM_writeLE24(dst, cBlockHeader24); + memcpy((BYTE*)dst + ZSTD_blockHeaderSize, src, srcSize); + return ZSTD_blockHeaderSize + srcSize; +} + static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize) { BYTE* const ostart = (BYTE* const)dst; @@ -2485,11 +2494,8 @@ static size_t ZSTD_compress_frameChunk (ZSTD_CCtx* cctx, if (ZSTD_isError(cSize)) return cSize; if (cSize == 0) { /* block is not compressible */ - U32 const cBlockHeader24 = lastBlock + (((U32)bt_raw)<<1) + (U32)(blockSize << 3); - if (blockSize + ZSTD_blockHeaderSize > dstCapacity) return ERROR(dstSize_tooSmall); - MEM_writeLE32(op, cBlockHeader24); /* 4th byte will be overwritten */ - memcpy(op + ZSTD_blockHeaderSize, ip, blockSize); - cSize = ZSTD_blockHeaderSize + blockSize; + cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock); + if (ZSTD_isError(cSize)) return cSize; } else { U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3); MEM_writeLE24(op, cBlockHeader24); From 73773c6b6a6f4dc96641d1951f3879bae1f7d553 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 27 Sep 2018 18:15:14 -0700 Subject: [PATCH 8/9] fixed legacy compilation tests for some reason, these tests started failing recently on CircleCI --- lib/legacy/zstd_v01.c | 6 ++++++ lib/legacy/zstd_v02.c | 6 ++++++ lib/legacy/zstd_v03.c | 6 ++++++ tests/legacy.c | 5 +++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/legacy/zstd_v01.c b/lib/legacy/zstd_v01.c index 6303e1cfc..c007e7ceb 100644 --- a/lib/legacy/zstd_v01.c +++ b/lib/legacy/zstd_v01.c @@ -668,11 +668,17 @@ static size_t FSE_initDStream(FSE_DStream_t* bitD, const void* srcBuffer, size_t switch(srcSize) { case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16); + /* fallthrough */ case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24); + /* fallthrough */ case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32); + /* fallthrough */ case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24; + /* fallthrough */ case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16; + /* fallthrough */ case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8; + /* fallthrough */ default:; } contain32 = ((const BYTE*)srcBuffer)[srcSize-1]; diff --git a/lib/legacy/zstd_v02.c b/lib/legacy/zstd_v02.c index 8bc0eceed..c09ef8cff 100644 --- a/lib/legacy/zstd_v02.c +++ b/lib/legacy/zstd_v02.c @@ -399,11 +399,17 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si switch(srcSize) { case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16); + /* fallthrough */ case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24); + /* fallthrough */ case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32); + /* fallthrough */ case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24; + /* fallthrough */ case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16; + /* fallthrough */ case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8; + /* fallthrough */ default:; } contain32 = ((const BYTE*)srcBuffer)[srcSize-1]; diff --git a/lib/legacy/zstd_v03.c b/lib/legacy/zstd_v03.c index 54445af57..0c4cdf688 100644 --- a/lib/legacy/zstd_v03.c +++ b/lib/legacy/zstd_v03.c @@ -402,11 +402,17 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si switch(srcSize) { case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16); + /* fallthrough */ case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24); + /* fallthrough */ case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32); + /* fallthrough */ case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24; + /* fallthrough */ case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16; + /* fallthrough */ case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8; + /* fallthrough */ default:; } contain32 = ((const BYTE*)srcBuffer)[srcSize-1]; diff --git a/tests/legacy.c b/tests/legacy.c index 847e1d25e..e1cf82f2f 100644 --- a/tests/legacy.c +++ b/tests/legacy.c @@ -36,7 +36,7 @@ size_t const COMPRESSED_SIZE = 917; const char* const EXPECTED; /* content is at end of file */ -int testSimpleAPI(void) +static int testSimpleAPI(void) { size_t const size = strlen(EXPECTED); char* const output = malloc(size); @@ -71,7 +71,8 @@ int testSimpleAPI(void) return 0; } -int testStreamingAPI(void) + +static int testStreamingAPI(void) { size_t const outBuffSize = ZSTD_DStreamOutSize(); char* const outBuff = malloc(outBuffSize); From ff36513556f6484d6570291d90fb25eb4c4f2751 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 27 Sep 2018 18:24:41 -0700 Subject: [PATCH 9/9] fixed longmatch test too --- tests/longmatch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/longmatch.c b/tests/longmatch.c index ed3861571..1271e9ab1 100644 --- a/tests/longmatch.c +++ b/tests/longmatch.c @@ -17,25 +17,25 @@ #define ZSTD_STATIC_LINKING_ONLY #include "zstd.h" -int compress(ZSTD_CStream *ctx, ZSTD_outBuffer out, const void *data, size_t size) { +static int +compress(ZSTD_CStream *ctx, ZSTD_outBuffer out, const void *data, size_t size) +{ ZSTD_inBuffer in = { data, size, 0 }; while (in.pos < in.size) { ZSTD_outBuffer tmp = out; const size_t rc = ZSTD_compressStream(ctx, &tmp, &in); - if (ZSTD_isError(rc)) { - return 1; - } + if (ZSTD_isError(rc)) return 1; } - { - ZSTD_outBuffer tmp = out; + { ZSTD_outBuffer tmp = out; const size_t rc = ZSTD_flushStream(ctx, &tmp); if (rc != 0) { return 1; } } return 0; } -int main(int argc, const char** argv) { - ZSTD_CStream *ctx; +int main(int argc, const char** argv) +{ + ZSTD_CStream* ctx; ZSTD_parameters params; size_t rc; unsigned windowLog;