From 15603d956663de18361ed5f06b3b02333ebbc9b1 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 18:58:16 -0800 Subject: Added static analyzer test in Visual --- examples/HCStreaming_ringBuffer.c | 0 visual/2012/datagen/datagen.vcxproj | 8 ++++++++ visual/2012/frametest/frametest.vcxproj | 8 ++++++++ visual/2012/fullbench/fullbench.vcxproj | 8 ++++++++ visual/2012/fuzzer/fuzzer.vcxproj | 8 ++++++++ visual/2012/lz4/lz4.vcxproj | 8 ++++++++ 6 files changed, 40 insertions(+) mode change 100755 => 100644 examples/HCStreaming_ringBuffer.c diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c old mode 100755 new mode 100644 diff --git a/visual/2012/datagen/datagen.vcxproj b/visual/2012/datagen/datagen.vcxproj index ea61533..685ec85 100644 --- a/visual/2012/datagen/datagen.vcxproj +++ b/visual/2012/datagen/datagen.vcxproj @@ -69,18 +69,22 @@ true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true @@ -90,6 +94,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +109,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -120,6 +126,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -138,6 +145,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console diff --git a/visual/2012/frametest/frametest.vcxproj b/visual/2012/frametest/frametest.vcxproj index b86f7de..0972238 100644 --- a/visual/2012/frametest/frametest.vcxproj +++ b/visual/2012/frametest/frametest.vcxproj @@ -69,18 +69,22 @@ true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true @@ -90,6 +94,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +109,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -120,6 +126,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -138,6 +145,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console diff --git a/visual/2012/fullbench/fullbench.vcxproj b/visual/2012/fullbench/fullbench.vcxproj index 11f8f45..f702fe8 100644 --- a/visual/2012/fullbench/fullbench.vcxproj +++ b/visual/2012/fullbench/fullbench.vcxproj @@ -69,18 +69,22 @@ true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true @@ -90,6 +94,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +109,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -120,6 +126,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -138,6 +145,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console diff --git a/visual/2012/fuzzer/fuzzer.vcxproj b/visual/2012/fuzzer/fuzzer.vcxproj index 4da822f..6f684b4 100644 --- a/visual/2012/fuzzer/fuzzer.vcxproj +++ b/visual/2012/fuzzer/fuzzer.vcxproj @@ -69,18 +69,22 @@ true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true @@ -90,6 +94,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +109,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -120,6 +126,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -138,6 +145,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console diff --git a/visual/2012/lz4/lz4.vcxproj b/visual/2012/lz4/lz4.vcxproj index 8ac9387..8197b38 100644 --- a/visual/2012/lz4/lz4.vcxproj +++ b/visual/2012/lz4/lz4.vcxproj @@ -69,18 +69,22 @@ true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true true $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true false $(SolutionDir)..\..\lib;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + true @@ -90,6 +94,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -104,6 +109,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -120,6 +126,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console @@ -138,6 +145,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + true Console -- cgit v0.12 From 6fe48b91832b9f8b5869a8a6d2a86b2b0d99988a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 19:43:12 -0800 Subject: changed datagen to remove one malloc --- Makefile | 2 +- programs/Makefile | 5 ++--- programs/datagen.c | 50 +++++++++++++++++++++++++++----------------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index d2c4a0f..d1b0d0c 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ # ################################################################ # Version number -export VERSION=130 +export VERSION=131 export RELEASE=r$(VERSION) DESTDIR?= diff --git a/programs/Makefile b/programs/Makefile index 43f1789..f422902 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -34,7 +34,7 @@ # datagen : generates synthetic data samples for tests & benchmarks # ########################################################################## -RELEASE?= r130 +RELEASE?= r131 DESTDIR?= PREFIX ?= /usr/local @@ -173,8 +173,7 @@ test-lz4-sparse: lz4 datagen echo "Hello World 3 !" | ./lz4 --no-frame-crc | ./lz4 -d -c @echo "\n Compatibility with Append :" ./datagen -P100 -g1M > tmp1M - cat tmp1M > tmp2M - cat tmp1M >> tmp2M + cat tmp1M tmp1M > tmp2M ./lz4 -B5 -v tmp1M tmpC ./lz4 -d -v tmpC tmpR ./lz4 -d -v tmpC >> tmpR diff --git a/programs/datagen.c b/programs/datagen.c index bccb21e..9df9da8 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -71,6 +71,17 @@ #define PRIME2 2246822519U +/************************************** +* Local types +**************************************/ +#define LTLOG 13 +#define LTSIZE (1< lastChar) character = firstChar; } - return lt; } -static char RDG_genChar(U32* seed, const void* ltctx) + +static BYTE RDG_genChar(U32* seed, const litDistribTable lt) { - const BYTE* lt = (const BYTE*)ltctx; U32 id = RDG_rand(seed) & LTMASK; - return lt[id]; + return (lt[id]); } + #define RDG_DICTSIZE (32 KB) #define RDG_RAND15BITS ((RDG_rand(seed) >> 3) & 32767) #define RDG_RANDLENGTH ( ((RDG_rand(seed) >> 7) & 7) ? (RDG_rand(seed) & 15) : (RDG_rand(seed) & 511) + 15) -void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double matchProba, void* litTable, unsigned* seedPtr) +void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double matchProba, litDistribTable lt, unsigned* seedPtr) { BYTE* buffPtr = (BYTE*)buffer; const U32 matchProba32 = (U32)(32768 * matchProba); size_t pos = prefixSize; - void* ldctx = litTable; U32* seed = seedPtr; /* special case */ @@ -146,11 +153,11 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match } memset(buffPtr+pos, 0, size0); pos += size0; - buffPtr[pos-1] = RDG_genChar(seed, ldctx); + buffPtr[pos-1] = RDG_genChar(seed, lt); } /* init */ - if (pos==0) buffPtr[0] = RDG_genChar(seed, ldctx), pos=1; + if (pos==0) buffPtr[0] = RDG_genChar(seed, lt), pos=1; /* Generate compressible data */ while (pos < buffSize) @@ -176,7 +183,7 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match size_t length = RDG_RANDLENGTH; d = pos + length; if (d > buffSize) d = buffSize; - while (pos < d) buffPtr[pos++] = RDG_genChar(seed, ldctx); + while (pos < d) buffPtr[pos++] = RDG_genChar(seed, lt); } } } @@ -184,11 +191,10 @@ 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) { - void* ldctx; + litDistribTable lt; if (litProba==0.0) litProba = matchProba / 4.5; - ldctx = RDG_createLiteralDistrib(litProba); - RDG_genBlock(buffer, size, 0, matchProba, ldctx, &seed); - free(ldctx); + RDG_fillLiteralDistrib(lt, litProba); + RDG_genBlock(buffer, size, 0, matchProba, lt, &seed); } @@ -198,26 +204,24 @@ void RDG_genOut(unsigned long long size, double matchProba, double litProba, uns BYTE buff[RDG_DICTSIZE + RDG_BLOCKSIZE]; U64 total = 0; size_t genBlockSize = RDG_BLOCKSIZE; - void* ldctx; + litDistribTable lt; /* init */ if (litProba==0.0) litProba = matchProba / 4.5; - ldctx = RDG_createLiteralDistrib(litProba); + RDG_fillLiteralDistrib(lt, litProba); SET_BINARY_MODE(stdout); /* Generate dict */ - RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, ldctx, &seed); + RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, lt, &seed); /* Generate compressible data */ while (total < size) { - RDG_genBlock(buff, RDG_DICTSIZE+RDG_BLOCKSIZE, RDG_DICTSIZE, matchProba, ldctx, &seed); + RDG_genBlock(buff, RDG_DICTSIZE+RDG_BLOCKSIZE, RDG_DICTSIZE, matchProba, lt, &seed); if (size-total < RDG_BLOCKSIZE) genBlockSize = (size_t)(size-total); total += genBlockSize; fwrite(buff, 1, genBlockSize, stdout); /* update dict */ memcpy(buff, buff + RDG_BLOCKSIZE, RDG_DICTSIZE); } - - free(ldctx); } -- cgit v0.12 From aa1350e1399c808d2de83668249fff83fe70a24e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 19:51:11 -0800 Subject: lz4hc : added one malloc test --- lib/lz4hc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index a22ab2b..bbe7a9d 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -701,6 +701,7 @@ int LZ4_resetStreamStateHC(void* state, char* inputBuffer) void* LZ4_createHC (char* inputBuffer) { void* hc4 = ALLOCATOR(1, sizeof(LZ4HC_Data_Structure)); + if (hc4 == NULL) return NULL; /* not enough memory */ LZ4HC_init ((LZ4HC_Data_Structure*)hc4, (const BYTE*)inputBuffer); ((LZ4HC_Data_Structure*)hc4)->inputBuffer = (BYTE*)inputBuffer; return hc4; -- cgit v0.12 From 81f19264ab3dfd5744110e55958572a11f900a4d Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 20:05:33 -0800 Subject: lz4cli : add one malloc test --- programs/lz4cli.c | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 977c04e..cc5c96a 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -503,6 +503,7 @@ int main(int argc, char** argv) { size_t l = strlen(input_filename); dynNameSpace = (char*)calloc(1,l+5); + if (dynNameSpace==NULL) exit(1); strcpy(dynNameSpace, input_filename); strcat(dynNameSpace, LZ4_EXTENSION); output_filename = dynNameSpace; -- cgit v0.12 From 1098d897a0c410306f0ac547c4b92e02922f8ddb Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 20:24:09 -0800 Subject: lz4io : removed one malloc --- programs/lz4io.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index 19db03b..d92634a 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -876,9 +876,11 @@ static unsigned long long LZ4IO_decompressLZ4F(dRess_t ress, FILE* srcFile, FILE } +#define PTSIZE (64 KB) +#define PTSIZET (PTSIZE / sizeof(size_t)) static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigned char MNstore[MAGICNUMBER_SIZE]) { - void* buffer = malloc(64 KB); + size_t buffer[PTSIZET]; size_t read = 1, sizeCheck; unsigned long long total = MAGICNUMBER_SIZE; unsigned storedSkips = 0; @@ -888,13 +890,12 @@ static unsigned long long LZ4IO_passThrough(FILE* finput, FILE* foutput, unsigne while (read) { - read = fread(buffer, 1, 64 KB, finput); + read = fread(buffer, 1, PTSIZE, finput); total += read; storedSkips = LZ4IO_fwriteSparse(foutput, buffer, read, storedSkips); } LZ4IO_fwriteSparseEnd(foutput, storedSkips); - free(buffer); return total; } -- cgit v0.12 From 8901dcdc9db3ea5d47900be903dfdb5070dc6b21 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sun, 28 Jun 2015 21:53:42 -0800 Subject: removed one malloc --- programs/lz4io.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/programs/lz4io.c b/programs/lz4io.c index d92634a..be2dc5d 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -1013,6 +1013,7 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file } +#define MAXSUFFIXSIZE 8 int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) { int i; @@ -1021,17 +1022,18 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); - char* ifnSuffix = (char*)malloc(suffixSize + 1); + const char* suffixPtr; dRess_t ress; + if (outFileName==NULL) exit(1); /* not enough memory */ ress = LZ4IO_createDResources(); for (i=0; i