diff --git a/lib/README.md b/lib/README.md index 6002118e..84e17a2f 100644 --- a/lib/README.md +++ b/lib/README.md @@ -27,11 +27,12 @@ To build the zstd library the following files are required: - decompress/zstd_decompress.c Stable API is exposed in [common/zstd.h]. -Advanced and experimental API is exposed in `common/zstd_static.h`. -`common/zstd_static.h` API elements should be used with static linking only, +Advanced and experimental API is exposed in [common/zstd_static.h]. +API elements of [common/zstd_static.h] should be used with static linking only, as their definition may change in future version of the library. [common/zstd.h]: common/zstd.h +[common/zstd_static.h]: common/zstd_static.h #### Separate compressor and decompressor diff --git a/lib/compress/zstd_opt.h b/lib/compress/zstd_opt.h index ae09a269..86fa1306 100644 --- a/lib/compress/zstd_opt.h +++ b/lib/compress/zstd_opt.h @@ -196,9 +196,10 @@ MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const B } /* match offset */ - seqStorePtr->offCodeSum++; - BYTE offCode = (BYTE)ZSTD_highbit(offset+1); - seqStorePtr->offCodeFreq[offCode]++; + { BYTE offCode = (BYTE)ZSTD_highbit(offset+1); + seqStorePtr->offCodeSum++; + seqStorePtr->offCodeFreq[offCode]++; + } /* match Length */ { static const BYTE ML_Code[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, @@ -462,7 +463,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx, const BYTE* inr; /* init */ - U32 rep[ZSTD_REP_INIT]; + U32 offset, rep[ZSTD_REP_INIT]; { U32 i; for (i=0; inextToUpdate3 = ctx->nextToUpdate; @@ -475,7 +476,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx, /* Match Loop */ while (ip < ilimit) { U32 cur, match_num, last_pos, litlen, price; - U32 u, mlen, best_mlen, best_off; + U32 u, mlen, best_mlen, best_off, litLength; memset(opt, 0, sizeof(ZSTD_optimal_t)); last_pos = 0; litlen = (U32)(ip - anchor); @@ -650,7 +651,6 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */ ZSTD_LOG_PARSER("%d: cur=%d/%d best_mlen=%d best_off=%d rep[0]=%d\n", (int)(ip-base+cur), (int)cur, (int)last_pos, (int)best_mlen, (int)best_off, opt[cur].rep[0]); opt[0].mlen = 1; - U32 offset; while (1) { mlen = opt[cur].mlen; @@ -674,8 +674,7 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */ if (mlen == 1) { ip++; cur++; continue; } offset = opt[cur].off; cur += mlen; - - U32 const litLength = (U32)(ip - anchor); + litLength = (U32)(ip - anchor); // ZSTD_LOG_ENCODE("%d/%d: ENCODE literals=%d mlen=%d off=%d rep[0]=%d rep[1]=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep[0], (int)rep[1]); if (offset >= ZSTD_REP_NUM) { @@ -746,10 +745,9 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx, ZSTD_optimal_t* opt = seqStorePtr->priceTable; ZSTD_match_t* matches = seqStorePtr->matchTable; const BYTE* inr; - U32 cur, match_num, last_pos, litlen, price; /* init */ - U32 rep[ZSTD_REP_INIT]; + U32 offset, rep[ZSTD_REP_INIT]; { U32 i; for (i=0; inextToUpdate3 = ctx->nextToUpdate; @@ -761,10 +759,8 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx, /* Match Loop */ while (ip < ilimit) { - U32 u; - U32 mlen=0; - U32 best_mlen=0; - U32 best_off=0; + U32 cur, match_num, last_pos, litlen, price; + U32 u, mlen, best_mlen, best_off, litLength; U32 current = (U32)(ip-base); memset(opt, 0, sizeof(ZSTD_optimal_t)); last_pos = 0; @@ -960,7 +956,6 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */ ZSTD_LOG_PARSER("%d: cur=%d/%d best_mlen=%d best_off=%d rep[0]=%d\n", (int)(ip-base+cur), (int)cur, (int)last_pos, (int)best_mlen, (int)best_off, opt[cur].rep[0]); opt[0].mlen = 1; - U32 offset; while (1) { mlen = opt[cur].mlen; @@ -984,8 +979,7 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */ if (mlen == 1) { ip++; cur++; continue; } offset = opt[cur].off; cur += mlen; - - U32 const litLength = (U32)(ip - anchor); + litLength = (U32)(ip - anchor); // ZSTD_LOG_ENCODE("%d/%d: ENCODE1 literals=%d mlen=%d off=%d rep[0]=%d rep[1]=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep[0], (int)rep[1]); if (offset >= ZSTD_REP_NUM) { diff --git a/lib/legacy/zstd_v05.c b/lib/legacy/zstd_v05.c index d5072479..75dc2a92 100644 --- a/lib/legacy/zstd_v05.c +++ b/lib/legacy/zstd_v05.c @@ -2372,9 +2372,6 @@ size_t HUFv05_decompress4X2_usingDTable( const U32 dtLog = DTable[0]; size_t errorCode; - /* Check */ - if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ - /* Init */ BITv05_DStream_t bitD1; BITv05_DStream_t bitD2; @@ -2398,6 +2395,9 @@ size_t HUFv05_decompress4X2_usingDTable( BYTE* op4 = opStart4; U32 endSignal; + /* Check */ + if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ + length4 = cSrcSize - (length1 + length2 + length3 + 6); if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */ errorCode = BITv05_initDStream(&bitD1, istart1, length1); @@ -3124,9 +3124,6 @@ size_t HUFv05_decompress4X6_usingDTable( const HUFv05_DSeqX6* ds = (const HUFv05_DSeqX6*)dsPtr; size_t errorCode; - /* Check */ - if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ - /* Init */ BITv05_DStream_t bitD1; BITv05_DStream_t bitD2; @@ -3150,6 +3147,9 @@ size_t HUFv05_decompress4X6_usingDTable( BYTE* op4 = opStart4; U32 endSignal; + /* Check */ + if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */ + length4 = cSrcSize - (length1 + length2 + length3 + 6); if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */ errorCode = BITv05_initDStream(&bitD1, istart1, length1); diff --git a/programs/bench.c b/programs/bench.c index 8470ed32..33c58c16 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -209,12 +209,13 @@ static U32 BMK_isDirectory(const char* infilename) #if defined(_MSC_VER) struct _stat64 statbuf; r = _stat64(infilename, &statbuf); + if (!r && (statbuf.st_mode & _S_IFDIR)) return 1; #else struct stat statbuf; r = stat(infilename, &statbuf); -#endif if (!r && S_ISDIR(statbuf.st_mode)) return 1; - return 0; +#endif + return 0; } /* ******************************************************** @@ -467,12 +468,12 @@ static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, benchResult_t result, total; int l; - SET_HIGH_PRIORITY; - const char* pch = strrchr(displayName, '\\'); /* Windows */ if (!pch) pch = strrchr(displayName, '/'); /* Linux */ if (pch) displayName = pch+1; + SET_HIGH_PRIORITY; + memset(&result, 0, sizeof(result)); memset(&total, 0, sizeof(total)); @@ -522,15 +523,15 @@ static void BMK_loadFiles(void* buffer, size_t bufferSize, const char** fileNamesTable, unsigned nbFiles) { size_t pos = 0, totalSize = 0; - + FILE* f; unsigned n; for (n=0; n bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */ diff --git a/visual/2013/fullbench/fullbench.vcxproj b/visual/2013/fullbench/fullbench.vcxproj index 8252d03d..6b878a99 100644 --- a/visual/2013/fullbench/fullbench.vcxproj +++ b/visual/2013/fullbench/fullbench.vcxproj @@ -28,8 +28,8 @@ Application true - v120 Unicode + v110 Application @@ -69,7 +69,7 @@ true - $(SolutionDir)..\..\lib;$(SolutionDir)..\..\lib\legacy;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\lib\common;$(SolutionDir)..\..\lib\legacy;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath) true @@ -160,27 +160,30 @@ - - - - - + + + + + + + + + - - - - + + + + + + + + + + - - - - - - - diff --git a/visual/2013/fullbench/fullbench.vcxproj.filters b/visual/2013/fullbench/fullbench.vcxproj.filters index 1d5f9c59..323b6446 100644 --- a/visual/2013/fullbench/fullbench.vcxproj.filters +++ b/visual/2013/fullbench/fullbench.vcxproj.filters @@ -1,81 +1,86 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - + {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - Fichiers sources + + Source Files + + + Source Files + + + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files + + + Source Files + + + Source Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files - Fichiers d%27en-tête + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête - - - Fichiers d%27en-tête + + Header Files - Fichiers d%27en-tête + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files \ No newline at end of file diff --git a/visual/2013/fuzzer/fuzzer.vcxproj b/visual/2013/fuzzer/fuzzer.vcxproj index 49738e0c..4b1875a9 100644 --- a/visual/2013/fuzzer/fuzzer.vcxproj +++ b/visual/2013/fuzzer/fuzzer.vcxproj @@ -1,4 +1,4 @@ - + @@ -28,8 +28,8 @@ Application true - v120 Unicode + v110 Application @@ -69,7 +69,7 @@ true - $(SolutionDir)..\..\lib;$(SolutionDir)..\..\lib\legacy;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\lib\common;$(SolutionDir)..\..\lib\legacy;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath) true @@ -160,29 +160,29 @@ - - - - - - - + + + + + + + - - - - + + + + + + + + + + - - - - - - diff --git a/visual/2013/fuzzer/fuzzer.vcxproj.filters b/visual/2013/fuzzer/fuzzer.vcxproj.filters index 500da875..3e0cbbed 100644 --- a/visual/2013/fuzzer/fuzzer.vcxproj.filters +++ b/visual/2013/fuzzer/fuzzer.vcxproj.filters @@ -1,90 +1,80 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - + {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - Fichiers sources - - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files - - Fichiers sources + + Source Files - - Fichiers sources - - - Fichiers sources + + Source Files - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - - Fichiers d%27en-tête + + Header Files - - Fichiers d%27en-tête + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files \ No newline at end of file diff --git a/visual/2013/zstd/zstd.vcxproj b/visual/2013/zstd/zstd.vcxproj index cced867e..7b2ebf6b 100755 --- a/visual/2013/zstd/zstd.vcxproj +++ b/visual/2013/zstd/zstd.vcxproj @@ -1,4 +1,4 @@ - + @@ -19,18 +19,22 @@ - - - + + + + + + + + + + + - - - - @@ -40,26 +44,25 @@ - - - - - + + + + + + + + + + + + + - - - - - - - - - @@ -78,7 +81,7 @@ Application true Unicode - v120 + v110 Application @@ -118,22 +121,22 @@ true - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); true true - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); true false - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); false false - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); false diff --git a/visual/2013/zstd/zstd.vcxproj.filters b/visual/2013/zstd/zstd.vcxproj.filters index eb894342..45f486fd 100755 --- a/visual/2013/zstd/zstd.vcxproj.filters +++ b/visual/2013/zstd/zstd.vcxproj.filters @@ -1,156 +1,161 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - + {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hpp;hxx;hm;inl;inc;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - Fichiers sources - - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources - - - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources - - - Fichiers sources - - - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources + Source Files - Fichiers sources + Source Files - Fichiers sources + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête - - - Fichiers d%27en-tête - - - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête + Header Files - Fichiers d%27en-tête - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources - - - Fichiers sources + Header Files - Fichiers d%27en-tête + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files - Fichiers d%27en-tête + Header Files \ No newline at end of file diff --git a/visual/2013/zstdlib/zstdlib.vcxproj b/visual/2013/zstdlib/zstdlib.vcxproj index e44699d4..89133f01 100644 --- a/visual/2013/zstdlib/zstdlib.vcxproj +++ b/visual/2013/zstdlib/zstdlib.vcxproj @@ -1,5 +1,5 @@ - - + + Debug @@ -19,24 +19,31 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -53,7 +60,7 @@ DynamicLibrary true Unicode - v120 + v110 DynamicLibrary @@ -95,28 +102,28 @@ true zstdlib_x86 $(Platform)\$(Configuration)\ - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); true true zstdlib_x64 $(Platform)\$(Configuration)\ - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); true false zstdlib_x86 $(Platform)\$(Configuration)\ - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); false false zstdlib_x64 $(Platform)\$(Configuration)\ - $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(SolutionDir)..\..\programs\legacy;$(SolutionDir)..\..\lib\legacy;$(SolutionDir)..\..\lib\common;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); false diff --git a/visual/2013/zstdlib/zstdlib.vcxproj.filters b/visual/2013/zstdlib/zstdlib.vcxproj.filters index ffb457b0..fa5bb166 100644 --- a/visual/2013/zstdlib/zstdlib.vcxproj.filters +++ b/visual/2013/zstdlib/zstdlib.vcxproj.filters @@ -15,63 +15,84 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + Source Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + Header Files