diff --git a/NEWS b/NEWS index 6a27ae2c..c34f3175 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +v0.7.4 +Modified : default compression level for CLI is 3 + v0.7.3 New : compression format specification New : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner. diff --git a/examples/dictionary_decompression.c b/examples/dictionary_decompression.c index 797075de..2d51f5e3 100644 --- a/examples/dictionary_decompression.c +++ b/examples/dictionary_decompression.c @@ -78,6 +78,7 @@ static void* loadFile_X(const char* fileName, size_t* size) static const ZSTD_DDict* createDict(const char* dictFileName) { size_t dictSize; + printf("loading dictionary %s \n", dictFileName); void* const dictBuffer = loadFile_X(dictFileName, &dictSize); const ZSTD_DDict* const ddict = ZSTD_createDDict(dictBuffer, dictSize); free(dictBuffer); diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index 3533bb61..301b5f91 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -239,7 +239,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits) /* repay normalized cost */ { U32 const noSymbol = 0xF0F0F0F0; - U32 rankLast[HUF_TABLELOG_MAX+1]; + U32 rankLast[HUF_TABLELOG_MAX+2]; int pos; /* Get pos of last (smallest) symbol per rank */ diff --git a/lib/dictBuilder/zdict.h b/lib/dictBuilder/zdict.h index 39acdf85..b96b828f 100644 --- a/lib/dictBuilder/zdict.h +++ b/lib/dictBuilder/zdict.h @@ -84,10 +84,6 @@ const char* ZDICT_getErrorName(size_t errorCode); * Use them only in association with static linking. * ==================================================================================== */ - -/*-************************************* -* Public type -***************************************/ typedef struct { unsigned selectivityLevel; /* 0 means default; larger => bigger selection => larger dictionary */ unsigned compressionLevel; /* 0 means default; target a specific zstd compression level */ @@ -97,9 +93,6 @@ typedef struct { } ZDICT_params_t; -/*-************************************* -* Public functions -***************************************/ /*! ZDICT_trainFromBuffer_advanced() : Same as ZDICT_trainFromBuffer() with control over more parameters. `parameters` is optional and can be provided with values set to 0 to mean "default". @@ -117,4 +110,4 @@ size_t ZDICT_trainFromBuffer_advanced(void* dictBuffer, size_t dictBufferCapacit } #endif -#endif +#endif /* DICTBUILDER_H_001 */ diff --git a/lib/legacy/zstd_v04.c b/lib/legacy/zstd_v04.c index c5bfa1e7..23ed133e 100644 --- a/lib/legacy/zstd_v04.c +++ b/lib/legacy/zstd_v04.c @@ -3620,36 +3620,26 @@ static size_t ZSTD_decompressContinue(ZSTD_DCtx* ctx, void* dst, size_t maxDstSi switch (ctx->stage) { case ZSTDds_getFrameHeaderSize : - { - /* get frame header size */ - if (srcSize != ZSTD_frameHeaderSize_min) return ERROR(srcSize_wrong); /* impossible */ - ctx->headerSize = ZSTD_decodeFrameHeader_Part1(ctx, src, ZSTD_frameHeaderSize_min); - if (ZSTD_isError(ctx->headerSize)) return ctx->headerSize; - memcpy(ctx->headerBuffer, src, ZSTD_frameHeaderSize_min); - if (ctx->headerSize > ZSTD_frameHeaderSize_min) - { - ctx->expected = ctx->headerSize - ZSTD_frameHeaderSize_min; - ctx->stage = ZSTDds_decodeFrameHeader; - return 0; - } - ctx->expected = 0; /* not necessary to copy more */ - } + /* get frame header size */ + if (srcSize != ZSTD_frameHeaderSize_min) return ERROR(srcSize_wrong); /* impossible */ + ctx->headerSize = ZSTD_decodeFrameHeader_Part1(ctx, src, ZSTD_frameHeaderSize_min); + if (ZSTD_isError(ctx->headerSize)) return ctx->headerSize; + memcpy(ctx->headerBuffer, src, ZSTD_frameHeaderSize_min); + if (ctx->headerSize > ZSTD_frameHeaderSize_min) return ERROR(GENERIC); /* impossible */ + ctx->expected = 0; /* not necessary to copy more */ + /* fallthrough */ case ZSTDds_decodeFrameHeader: - { - /* get frame header */ - size_t result; - memcpy(ctx->headerBuffer + ZSTD_frameHeaderSize_min, src, ctx->expected); - result = ZSTD_decodeFrameHeader_Part2(ctx, ctx->headerBuffer, ctx->headerSize); + /* get frame header */ + { size_t const result = ZSTD_decodeFrameHeader_Part2(ctx, ctx->headerBuffer, ctx->headerSize); if (ZSTD_isError(result)) return result; ctx->expected = ZSTD_blockHeaderSize; ctx->stage = ZSTDds_decodeBlockHeader; return 0; } case ZSTDds_decodeBlockHeader: - { - /* Decode block header */ - blockProperties_t bp; - size_t blockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp); + /* Decode block header */ + { blockProperties_t bp; + size_t const blockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp); if (ZSTD_isError(blockSize)) return blockSize; if (bp.blockType == bt_end) { diff --git a/lib/legacy/zstd_v05.c b/lib/legacy/zstd_v05.c index 9c57d18f..f3c720fd 100644 --- a/lib/legacy/zstd_v05.c +++ b/lib/legacy/zstd_v05.c @@ -3872,25 +3872,17 @@ size_t ZSTDv05_decompressContinue(ZSTDv05_DCtx* dctx, void* dst, size_t maxDstSi switch (dctx->stage) { case ZSTDv05ds_getFrameHeaderSize : - { - /* get frame header size */ - if (srcSize != ZSTDv05_frameHeaderSize_min) return ERROR(srcSize_wrong); /* impossible */ - dctx->headerSize = ZSTDv05_decodeFrameHeader_Part1(dctx, src, ZSTDv05_frameHeaderSize_min); - if (ZSTDv05_isError(dctx->headerSize)) return dctx->headerSize; - memcpy(dctx->headerBuffer, src, ZSTDv05_frameHeaderSize_min); - if (dctx->headerSize > ZSTDv05_frameHeaderSize_min) { - dctx->expected = dctx->headerSize - ZSTDv05_frameHeaderSize_min; - dctx->stage = ZSTDv05ds_decodeFrameHeader; - return 0; - } - dctx->expected = 0; /* not necessary to copy more */ - } + /* get frame header size */ + if (srcSize != ZSTDv05_frameHeaderSize_min) return ERROR(srcSize_wrong); /* impossible */ + dctx->headerSize = ZSTDv05_decodeFrameHeader_Part1(dctx, src, ZSTDv05_frameHeaderSize_min); + if (ZSTDv05_isError(dctx->headerSize)) return dctx->headerSize; + memcpy(dctx->headerBuffer, src, ZSTDv05_frameHeaderSize_min); + if (dctx->headerSize > ZSTDv05_frameHeaderSize_min) return ERROR(GENERIC); /* should never happen */ + dctx->expected = 0; /* not necessary to copy more */ + /* fallthrough */ case ZSTDv05ds_decodeFrameHeader: - { - /* get frame header */ - size_t result; - memcpy(dctx->headerBuffer + ZSTDv05_frameHeaderSize_min, src, dctx->expected); - result = ZSTDv05_decodeFrameHeader_Part2(dctx, dctx->headerBuffer, dctx->headerSize); + /* get frame header */ + { size_t const result = ZSTDv05_decodeFrameHeader_Part2(dctx, dctx->headerBuffer, dctx->headerSize); if (ZSTDv05_isError(result)) return result; dctx->expected = ZSTDv05_blockHeaderSize; dctx->stage = ZSTDv05ds_decodeBlockHeader; diff --git a/programs/datagen.c b/programs/datagen.c index 0b3dce2e..6cb5111f 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -30,7 +30,7 @@ /*-************************************ -* Includes +* Dependencies **************************************/ #include /* malloc */ #include /* FILE, fwrite, fprintf */ @@ -94,12 +94,10 @@ static void RDG_fillLiteralDistrib(BYTE* ldt, double ld) U32 u; if (ld<=0.0) ld = 0.0; - //TRACE(" percent:%5.2f%% \n", ld*100.); - //TRACE(" start:(%c)[%02X] ", character, character); for (u=0; u lastChar) character = firstChar; } @@ -109,8 +107,6 @@ static void RDG_fillLiteralDistrib(BYTE* ldt, double ld) static BYTE RDG_genChar(U32* seed, const BYTE* ldt) { U32 const id = RDG_rand(seed) & LTMASK; - //TRACE(" %u : \n", id); - //TRACE(" %4u [%4u] ; val : %4u \n", id, id&255, ldt[id]); return ldt[id]; /* memory-sanitizer fails here, stating "uninitialized value" when table initialized with P==0.0. Checked : table is fully initialized */ } @@ -162,7 +158,6 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match U32 const randOffset = RDG_rand15Bits(seedPtr) + 1; U32 const offset = repeatOffset ? prevOffset : (U32) MIN(randOffset , pos); size_t match = pos - offset; - //TRACE("pos : %u; offset: %u ; length : %u \n", (U32)pos, offset, length); while (pos < d) buffPtr[pos++] = buffPtr[match++]; /* correctly manages overlaps */ prevOffset = offset; } else { @@ -177,9 +172,8 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match void RDG_genBuffer(void* buffer, size_t size, double matchProba, double litProba, unsigned seed) { BYTE ldt[LTSIZE]; - memset(ldt, '0', sizeof(ldt)); + memset(ldt, '0', sizeof(ldt)); /* yes, character '0', this is intentional */ if (litProba<=0.0) litProba = matchProba / 4.5; - //TRACE(" percent:%5.2f%% \n", litProba*100.); RDG_fillLiteralDistrib(ldt, litProba); RDG_genBlock(buffer, size, 0, matchProba, ldt, &seed); } @@ -196,7 +190,7 @@ void RDG_genStdout(unsigned long long size, double matchProba, double litProba, /* init */ if (buff==NULL) { fprintf(stderr, "datagen: error: %s \n", strerror(errno)); exit(1); } if (litProba<=0.0) litProba = matchProba / 4.5; - memset(ldt, '0', sizeof(ldt)); + memset(ldt, '0', sizeof(ldt)); /* yes, character '0', this is intentional */ RDG_fillLiteralDistrib(ldt, litProba); SET_BINARY_MODE(stdout); diff --git a/programs/fileio.c b/programs/fileio.c index fb2dda7a..492dc914 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -273,11 +273,10 @@ typedef struct { static cRess_t FIO_createCResources(const char* dictFileName) { cRess_t ress; + memset(&ress, 0, sizeof(ress)); ress.ctx = ZBUFF_createCCtx(); if (ress.ctx == NULL) EXM_THROW(30, "zstd: allocation error : can't create ZBUFF context"); - - /* Allocate Memory */ ress.srcBufferSize = ZBUFF_recommendedCInSize(); ress.srcBuffer = malloc(ress.srcBufferSize); ress.dstBufferSize = ZBUFF_recommendedCOutSize(); @@ -502,12 +501,11 @@ typedef struct { static dRess_t FIO_createDResources(const char* dictFileName) { dRess_t ress; + memset(&ress, 0, sizeof(ress)); - /* init */ + /* Allocation */ ress.dctx = ZBUFF_createDCtx(); if (ress.dctx==NULL) EXM_THROW(60, "Can't create ZBUFF decompression context"); - - /* Allocate Memory */ ress.srcBufferSize = ZBUFF_recommendedDInSize(); ress.srcBuffer = malloc(ress.srcBufferSize); ress.dstBufferSize = ZBUFF_recommendedDOutSize(); @@ -710,6 +708,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName) return FIO_passThrough(dstFile, srcFile, ress.srcBuffer, ress.srcBufferSize); else { DISPLAYLEVEL(1, "zstd: %s: not in zstd format \n", srcFileName); + fclose(srcFile); return 1; } } } filesize += FIO_decompressFrame(ress, dstFile, srcFile, toRead); diff --git a/programs/zstdcli.c b/programs/zstdcli.c index edc87a00..7b41865d 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -462,6 +462,7 @@ int main(int argCount, const char** argv) if (dictBuild) { #ifndef ZSTD_NODICT ZDICT_params_t dictParams; + memset(&dictParams, 0, sizeof(dictParams)); dictParams.compressionLevel = dictCLevel; dictParams.selectivityLevel = dictSelect; dictParams.notificationLevel = displayLevel;