diff --git a/lib/zbuff.c b/lib/zbuff.c index 721fad227..b0225e857 100644 --- a/lib/zbuff.c +++ b/lib/zbuff.c @@ -26,14 +26,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. You can contact the author at : - - zstd source repository : https://github.com/Cyan4973/zstd - - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c + - zstd homepage : http://www.zstd.net/ */ -/* The objects defined into this file should be considered experimental. - * They are not labelled stable, as their prototype may change in the future. - * You can use them for tests, provide feedback, or if you can endure risk of future changes. - */ /* ************************************* * Dependencies @@ -281,7 +276,7 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr) BYTE* op = ostart; size_t outSize = *dstCapacityPtr; size_t epilogueSize, remaining; - ZBUFF_compressFlush(zbc, dst, &outSize); /* flush any remaining inBuff */ + ZBUFF_compressFlush(zbc, dst, &outSize); /* flush any remaining inBuff */ op += outSize; epilogueSize = ZSTD_compressEnd(zbc->zc, zbc->outBuff + zbc->outBuffContentSize, zbc->outBuffSize - zbc->outBuffContentSize); /* epilogue into outBuff */ zbc->outBuffContentSize += epilogueSize; @@ -289,7 +284,7 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr) zbc->stage = ZBUFFcs_flush; remaining = ZBUFF_compressFlush(zbc, op, &outSize); /* attempt to flush epilogue into dst */ op += outSize; - if (!remaining) zbc->stage = ZBUFFcs_init; /* close only if nothing left to flush */ + if (!remaining) zbc->stage = ZBUFFcs_init; /* close only if nothing left to flush */ *dstCapacityPtr = op-ostart; /* tells how many bytes were written */ return remaining; } @@ -466,6 +461,7 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, zbc->stage = ZBUFFds_flush; // break; /* ZBUFFds_flush follows */ } } + case ZBUFFds_flush: { size_t const toFlushSize = zbc->outEnd - zbc->outStart; size_t const flushedSize = ZBUFF_limitCopy(op, oend-op, zbc->outBuff + zbc->outStart, toFlushSize); diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 5fe078fcd..6905dcbf6 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -141,8 +141,7 @@ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) /* hidden interface * @return : 0, or an error code if one value is beyond authorized range */ size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams) { - { U32 const windowLog_max = MEM_32bits() ? 25 : ZSTD_WINDOWLOG_MAX; /* 32 bits mode cannot flush > 24 bits */ - CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, windowLog_max); } + CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); CLAMPCHECK(cParams.contentLog, ZSTD_CONTENTLOG_MIN, ZSTD_CONTENTLOG_MAX); CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX); CLAMPCHECK(cParams.searchLog, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX); @@ -2413,7 +2412,6 @@ size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcS #define ZSTD_MAX_CLEVEL 22 unsigned ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } - static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { { /* "default" */ /* W, C, H, S, L, SL, strat */ @@ -2526,14 +2524,16 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV * `srcSize` value is optional, select 0 if not known */ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, size_t dictSize) { + ZSTD_compressionParameters cp; size_t addedSize = srcSize ? 0 : 500; - U64 rSize = srcSize+dictSize ? srcSize+dictSize+addedSize : (U64)-1; + U64 const rSize = srcSize+dictSize ? srcSize+dictSize+addedSize : (U64)-1; U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB); /* intentional underflow for srcSizeHint == 0 */ if (compressionLevel<=0) compressionLevel = 1; if (compressionLevel > ZSTD_MAX_CLEVEL) compressionLevel = ZSTD_MAX_CLEVEL; #if ZSTD_OPT_DEBUG >= 1 tableID=0; #endif - return ZSTD_defaultCParameters[tableID][compressionLevel]; + cp = ZSTD_defaultCParameters[tableID][compressionLevel]; + if (cp.windowLog > ZSTD_WINDOWLOG_MAX) cp.windowLog = ZSTD_WINDOWLOG_MAX; /* auto-correction, for 32-bits mode */ + return cp; } - diff --git a/lib/zstd_static.h b/lib/zstd_static.h index 350859f79..ecc5ff58b 100644 --- a/lib/zstd_static.h +++ b/lib/zstd_static.h @@ -57,7 +57,7 @@ extern "C" { /*-************************************* * Types ***************************************/ -#define ZSTD_WINDOWLOG_MAX 27 +#define ZSTD_WINDOWLOG_MAX (MEM_32bits() ? 25 : 27) #define ZSTD_WINDOWLOG_MIN 18 #define ZSTD_CONTENTLOG_MAX (ZSTD_WINDOWLOG_MAX+1) #define ZSTD_CONTENTLOG_MIN 4 diff --git a/programs/zbufftest.c b/programs/zbufftest.c index cb8e0bba6..f44f5d5e5 100644 --- a/programs/zbufftest.c +++ b/programs/zbufftest.c @@ -134,12 +134,12 @@ static unsigned FUZ_highbit32(U32 v32) static int basicUnitTests(U32 seed, double compressibility) { int testResult = 0; - void* CNBuffer; size_t CNBufferSize = COMPRESSIBLE_NOISE_LENGTH; - void* compressedBuffer; - size_t compressedBufferSize = ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH); - void* decodedBuffer; - size_t decodedBufferSize = CNBufferSize; + void* CNBuffer = malloc(CNBufferSize); + size_t const compressedBufferSize = ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH); + void* compressedBuffer = malloc(compressedBufferSize); + size_t const decodedBufferSize = CNBufferSize; + void* decodedBuffer = malloc(decodedBufferSize); U32 randState = seed; size_t result, cSize, readSize, genSize; U32 testNb=0; @@ -147,9 +147,6 @@ static int basicUnitTests(U32 seed, double compressibility) ZBUFF_DCtx* zd = ZBUFF_createDCtx(); /* Create compressible test buffer */ - CNBuffer = malloc(CNBufferSize); - compressedBuffer = malloc(compressedBufferSize); - decodedBuffer = malloc(decodedBufferSize); if (!CNBuffer || !compressedBuffer || !decodedBuffer || !zc || !zd) { DISPLAY("Not enough memory, aborting\n"); goto _output_error; @@ -242,7 +239,7 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres BYTE* cNoiseBuffer[5]; size_t srcBufferSize = (size_t)1<