summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrzemyslaw Skibinski <inikep@gmail.com>2016-11-16 08:01:45 (GMT)
committerPrzemyslaw Skibinski <inikep@gmail.com>2016-11-16 08:01:45 (GMT)
commit7b6a9d86383579099fd174000b857a5ea1671f0b (patch)
tree9e1dd4dbed190a957cbd580a20d9c0fb39ca9ad0
parent2e10aab20f17adfffb2379e828124be12c774779 (diff)
downloadlz4-7b6a9d86383579099fd174000b857a5ea1671f0b.zip
lz4-7b6a9d86383579099fd174000b857a5ea1671f0b.tar.gz
lz4-7b6a9d86383579099fd174000b857a5ea1671f0b.tar.bz2
Merge remote-tracking branch 'refs/remotes/lz4/dev' into dev
-rw-r--r--README.md6
-rw-r--r--appveyor.yml18
-rw-r--r--lib/lz4.h2
-rw-r--r--lib/lz4frame.c37
-rw-r--r--programs/bench.c1
-rw-r--r--programs/datagen.c29
-rw-r--r--programs/lz4.13
-rw-r--r--programs/lz4cli.c22
-rw-r--r--programs/lz4io.c12
-rw-r--r--programs/lz4io.h16
10 files changed, 68 insertions, 78 deletions
diff --git a/README.md b/README.md
index b0033f2..91661a9 100644
--- a/README.md
+++ b/README.md
@@ -25,9 +25,9 @@ LZ4 library is provided as open-source software using BSD 2-Clause license.
[travisMasterBadge]: https://travis-ci.org/lz4/lz4.svg?branch=master "Continuous Integration test suite"
[travisDevBadge]: https://travis-ci.org/lz4/lz4.svg?branch=dev "Continuous Integration test suite"
[travisLink]: https://travis-ci.org/lz4/lz4
-[AppveyorMasterBadge]: https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq/branch/master?svg=true "Visual test suite"
-[AppveyorDevBadge]: https://ci.appveyor.com/api/projects/status/v6kxv9si529477cq/branch/dev?svg=true "Visual test suite"
-[AppveyorLink]: https://ci.appveyor.com/project/YannCollet/lz4
+[AppveyorMasterBadge]: https://ci.appveyor.com/api/projects/status/jc2yhgwyc7qqtsko/branch/master?svg=true "Windows test suite"
+[AppveyorDevBadge]: https://ci.appveyor.com/api/projects/status/jc2yhgwyc7qqtsko/branch/dev?svg=true "Windows test suite"
+[AppveyorLink]: https://ci.appveyor.com/project/YannCollet/lz4-1lndh
[coverBadge]: https://scan.coverity.com/projects/4735/badge.svg "Static code analysis of Master branch"
[coverlink]: https://scan.coverity.com/projects/4735
diff --git a/appveyor.yml b/appveyor.yml
index 37f3bd5..210f5d7 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -34,9 +34,9 @@ install:
)
build_script:
- - if [%PLATFORM%]==[mingw32] SET PATH=%PATH_MINGW32%;%PATH_ORIGINAL%
- - if [%PLATFORM%]==[mingw64] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL%
- - if [%PLATFORM%]==[clang] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL%
+ - if [%PLATFORM%]==[mingw32] SET PATH=%PATH_MINGW32%;%PATH_ORIGINAL%
+ - if [%PLATFORM%]==[mingw64] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL%
+ - if [%PLATFORM%]==[clang] SET PATH=%PATH_MINGW64%;%PATH_ORIGINAL%
- ECHO *** &&
ECHO Building %COMPILER% %PLATFORM% %CONFIGURATION% &&
ECHO ***
@@ -108,11 +108,11 @@ test_script:
- if not [%COMPILER%]==[unknown] (
CD programs &&
lz4 -h &&
- lz4 -i1b lz4.exe &&
+ lz4 -i1b lz4.exe &&
lz4 -i1b5 lz4.exe &&
lz4 -i1b10 lz4.exe &&
lz4 -i1b15 lz4.exe &&
- echo ------- lz4 tested ------- &&
+ echo ------- lz4 tested ------- &&
fullbench.exe -i1 fullbench.exe
)
@@ -125,7 +125,7 @@ artifacts:
deploy:
- provider: GitHub
auth_token:
- secure: LgJo8emYc3sFnlNWkGl4/VYK3nk/8+RagcsqDlAi3xeqNGNutnKjcftjg84uJoT4
+ secure: w6UJaGie0qbZvffr/fqyhO/Vj8rMiQWnv9a8qm3gxfngdHDTMT42wYupqJpIExId
artifact: bin\lz4.exe
force_update: true
on:
@@ -135,7 +135,7 @@ deploy:
- provider: GitHub
auth_token:
- secure: LgJo8emYc3sFnlNWkGl4/VYK3nk/8+RagcsqDlAi3xeqNGNutnKjcftjg84uJoT4
+ secure: w6UJaGie0qbZvffr/fqyhO/Vj8rMiQWnv9a8qm3gxfngdHDTMT42wYupqJpIExId
artifact: bin\lz4_32.exe
force_update: true
on:
@@ -145,7 +145,7 @@ deploy:
- provider: GitHub
auth_token:
- secure: LgJo8emYc3sFnlNWkGl4/VYK3nk/8+RagcsqDlAi3xeqNGNutnKjcftjg84uJoT4
+ secure: w6UJaGie0qbZvffr/fqyhO/Vj8rMiQWnv9a8qm3gxfngdHDTMT42wYupqJpIExId
artifact: bin\liblz4_x64.zip
force_update: true
on:
@@ -155,7 +155,7 @@ deploy:
- provider: GitHub
auth_token:
- secure: LgJo8emYc3sFnlNWkGl4/VYK3nk/8+RagcsqDlAi3xeqNGNutnKjcftjg84uJoT4
+ secure: w6UJaGie0qbZvffr/fqyhO/Vj8rMiQWnv9a8qm3gxfngdHDTMT42wYupqJpIExId
artifact: bin\liblz4_x86.zip
force_update: true
on:
diff --git a/lib/lz4.h b/lib/lz4.h
index c1ea91a..babd78c 100644
--- a/lib/lz4.h
+++ b/lib/lz4.h
@@ -85,7 +85,7 @@ extern "C" {
/*========== Version =========== */
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
#define LZ4_VERSION_MINOR 7 /* for new (non-breaking) interface capabilities */
-#define LZ4_VERSION_RELEASE 2 /* for tweaks, bug-fixes, or development */
+#define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
diff --git a/lib/lz4frame.c b/lib/lz4frame.c
index c31f82d..c8e5bde 100644
--- a/lib/lz4frame.c
+++ b/lib/lz4frame.c
@@ -817,9 +817,8 @@ static size_t LZ4F_headerSize(const void* src, size_t srcSize)
*/
static size_t LZ4F_decodeHeader(LZ4F_dctx* dctxPtr, const void* src, size_t srcSize)
{
- BYTE FLG, BD, HC;
+ BYTE FLG, BD;
unsigned version, blockMode, blockChecksumFlag, contentSizeFlag, contentChecksumFlag, blockSizeID;
- size_t bufferNeeded;
size_t frameHeaderSize;
const BYTE* srcPtr = (const BYTE*)src;
@@ -877,9 +876,9 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx* dctxPtr, const void* src, size_t srcS
if (blockSizeID < 4) return err0r(LZ4F_ERROR_maxBlockSize_invalid); /* 4-7 only supported values for the time being */
if (((BD>>0)&_4BITS) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); /* Reserved bits */
- /* check */
- HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5);
- if (HC != srcPtr[frameHeaderSize-1]) return err0r(LZ4F_ERROR_headerChecksum_invalid); /* Bad header checksum error */
+ /* check header */
+ { BYTE const HC = LZ4F_headerChecksum(srcPtr+4, frameHeaderSize-5);
+ if (HC != srcPtr[frameHeaderSize-1]) return err0r(LZ4F_ERROR_headerChecksum_invalid); }
/* save */
dctxPtr->frameInfo.blockMode = (LZ4F_blockMode_t)blockMode;
@@ -892,17 +891,17 @@ static size_t LZ4F_decodeHeader(LZ4F_dctx* dctxPtr, const void* src, size_t srcS
/* init */
if (contentChecksumFlag) XXH32_reset(&(dctxPtr->xxh), 0);
- /* alloc */
- bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB);
- if (bufferNeeded > dctxPtr->maxBufferSize) { /* tmp buffers too small */
- FREEMEM(dctxPtr->tmpIn);
- FREEMEM(dctxPtr->tmpOutBuffer);
- dctxPtr->maxBufferSize = bufferNeeded;
- dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize);
- if (dctxPtr->tmpIn == NULL) return err0r(LZ4F_ERROR_GENERIC);
- dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(dctxPtr->maxBufferSize);
- if (dctxPtr->tmpOutBuffer== NULL) return err0r(LZ4F_ERROR_GENERIC);
- }
+ /* internal buffers allocation */
+ { size_t const bufferNeeded = dctxPtr->maxBlockSize + ((dctxPtr->frameInfo.blockMode==LZ4F_blockLinked) * 128 KB);
+ if (bufferNeeded > dctxPtr->maxBufferSize) { /* tmp buffers too small */
+ FREEMEM(dctxPtr->tmpIn);
+ dctxPtr->tmpIn = (BYTE*)ALLOCATOR(dctxPtr->maxBlockSize);
+ if (dctxPtr->tmpIn == NULL) return err0r(LZ4F_ERROR_allocation_failed);
+ dctxPtr->maxBufferSize = bufferNeeded;
+ FREEMEM(dctxPtr->tmpOutBuffer);
+ dctxPtr->tmpOutBuffer= (BYTE*)ALLOCATOR(bufferNeeded);
+ if (dctxPtr->tmpOutBuffer== NULL) return err0r(LZ4F_ERROR_allocation_failed);
+ } }
dctxPtr->tmpInSize = 0;
dctxPtr->tmpInTarget = 0;
dctxPtr->dict = dctxPtr->tmpOutBuffer;
@@ -981,9 +980,9 @@ static void LZ4F_updateDict(LZ4F_dctx* dctxPtr, const BYTE* dstPtr, size_t dstSi
}
if (withinTmp) { /* copy relevant dict portion in front of tmpOut within tmpOutBuffer */
- size_t preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
+ size_t const preserveSize = dctxPtr->tmpOut - dctxPtr->tmpOutBuffer;
size_t copySize = 64 KB - dctxPtr->tmpOutSize;
- const BYTE* oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
+ const BYTE* const oldDictEnd = dctxPtr->dict + dctxPtr->dictSize - dctxPtr->tmpOutStart;
if (dctxPtr->tmpOutSize > 64 KB) copySize = 0;
if (copySize > preserveSize) copySize = preserveSize;
@@ -996,7 +995,7 @@ static void LZ4F_updateDict(LZ4F_dctx* dctxPtr, const BYTE* dstPtr, size_t dstSi
if (dctxPtr->dict == dctxPtr->tmpOutBuffer) { /* copy dst into tmp to complete dict */
if (dctxPtr->dictSize + dstSize > dctxPtr->maxBufferSize) { /* tmp buffer not large enough */
- size_t preserveSize = 64 KB - dstSize; /* note : dstSize < 64 KB */
+ size_t const preserveSize = 64 KB - dstSize; /* note : dstSize < 64 KB */
memcpy(dctxPtr->tmpOutBuffer, dctxPtr->dict + dctxPtr->dictSize - preserveSize, preserveSize);
dctxPtr->dictSize = preserveSize;
}
diff --git a/programs/bench.c b/programs/bench.c
index cfd60db..434da8b 100644
--- a/programs/bench.c
+++ b/programs/bench.c
@@ -260,6 +260,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
cSize = 0;
{ U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
+ cSize += !cSize; /* avoid div by 0 */
ratio = (double)srcSize / (double)cSize;
markNb = (markNb+1) % NB_MARKS;
DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r",
diff --git a/programs/datagen.c b/programs/datagen.c
index d851418..ed37c2a 100644
--- a/programs/datagen.c
+++ b/programs/datagen.c
@@ -81,10 +81,10 @@ typedef BYTE litDistribTable[LTSIZE];
-
/*********************************************************
* Local Functions
*********************************************************/
+#define MIN(a,b) ( (a) < (b) ? (a) :(b) )
#define RDG_rotl32(x,r) ((x << r) | (x >> (32 - r)))
static unsigned int RDG_rand(U32* src)
{
@@ -99,24 +99,15 @@ static unsigned int RDG_rand(U32* src)
static void RDG_fillLiteralDistrib(litDistribTable lt, double ld)
{
- U32 i = 0;
- BYTE character = '0';
- BYTE firstChar = '(';
- BYTE lastChar = '}';
-
- if (ld==0.0)
- {
- character = 0;
- firstChar = 0;
- lastChar =255;
- }
- while (i<LTSIZE)
- {
- U32 weight = (U32)((double)(LTSIZE - i) * ld) + 1;
- U32 end;
- if (weight + i > LTSIZE) weight = LTSIZE-i;
- end = i + weight;
- while (i < end) lt[i++] = character;
+ BYTE const firstChar = ld <= 0.0 ? 0 : '(';
+ BYTE const lastChar = ld <= 0.0 ? 255 : '}';
+ BYTE character = ld <= 0.0 ? 0 : '0';
+ U32 u = 0;
+
+ while (u<LTSIZE) {
+ U32 const weight = (U32)((double)(LTSIZE - u) * ld) + 1;
+ U32 const end = MIN(u+weight, LTSIZE);
+ while (u < end) lt[u++] = character;
character++;
if (character > lastChar) character = firstChar;
}
diff --git a/programs/lz4.1 b/programs/lz4.1
index 434b131..2c94033 100644
--- a/programs/lz4.1
+++ b/programs/lz4.1
@@ -207,7 +207,8 @@ hence for a file. It won't work with unknown source size, such as stdin or pipe.
sparse mode support (default:enabled on file, disabled on stdout)
.TP
.B \-l
- use Legacy format (useful for Linux Kernel compression)
+ use Legacy format (typically used for Linux Kernel compression)
+ note : \fB-l\fR is not compatible with \fB-m\fR (\fB--multiple\fR)
.
.SS "Other options"
.TP
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 88fbb53..297ce6b 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -288,11 +288,11 @@ int main(int argc, const char** argv)
const char* input_filename = NULL;
const char* output_filename= NULL;
char* dynNameSpace = NULL;
- const char** inFileNames = NULL;
+ const char** inFileNames = (const char**) calloc(argc, sizeof(char*));
unsigned ifnIdx=0;
const char nullOutput[] = NULL_OUTPUT;
const char extension[] = LZ4_EXTENSION;
- int blockSize = LZ4IO_setBlockSizeID(LZ4_BLOCKSIZEID_DEFAULT);
+ size_t blockSize = LZ4IO_setBlockSizeID(LZ4_BLOCKSIZEID_DEFAULT);
const char* const exeName = argv[0];
#ifdef UTIL_HAS_CREATEFILELIST
const char** extendedFileList = NULL;
@@ -301,6 +301,10 @@ int main(int argc, const char** argv)
#endif
/* Init */
+ if (inFileNames==NULL) {
+ DISPLAY("Allocation error : not enough memory \n");
+ return 1;
+ }
LZ4IO_setOverwrite(0);
/* lz4cat predefined behavior */
@@ -311,8 +315,6 @@ int main(int argc, const char** argv)
output_filename=stdoutmark;
displayLevel=1;
multiple_inputs=1;
- inFileNames = (const char**) calloc(argc, sizeof(char*));
- if (inFileNames==NULL) { perror(exeName); exit(1); }
}
if (!strcmp(exeName, UNLZ4)) { mode = om_decompress; }
@@ -336,7 +338,7 @@ int main(int argc, const char** argv)
if (!strcmp(argument, "--compress")) { mode = om_compress; continue; }
if ((!strcmp(argument, "--decompress"))
|| (!strcmp(argument, "--uncompress"))) { mode = om_decompress; continue; }
- if (!strcmp(argument, "--multiple")) { multiple_inputs = 1; if (inFileNames==NULL) inFileNames = (const char**)malloc(argc * sizeof(char*)); continue; }
+ if (!strcmp(argument, "--multiple")) { multiple_inputs = 1; continue; }
if (!strcmp(argument, "--test")) { mode = om_test; continue; }
if (!strcmp(argument, "--force")) { LZ4IO_setOverwrite(1); continue; }
if (!strcmp(argument, "--no-force")) { LZ4IO_setOverwrite(0); continue; }
@@ -454,10 +456,6 @@ int main(int argc, const char** argv)
/* Benchmark */
case 'b': mode = om_bench; multiple_inputs=1;
- if (inFileNames == NULL) {
- inFileNames = (const char**) calloc(argc, sizeof(char*));
- if (inFileNames==NULL) { perror(exeName); exit(1); }
- }
break;
#ifdef UTIL_HAS_CREATEFILELIST
@@ -466,10 +464,6 @@ int main(int argc, const char** argv)
#endif
/* Treat non-option args as input files. See https://code.google.com/p/lz4/issues/detail?id=151 */
case 'm': multiple_inputs=1;
- if (inFileNames == NULL) {
- inFileNames = (const char**) calloc(argc, sizeof(char*));
- if (inFileNames==NULL) { perror(exeName); exit(1); }
- }
break;
/* Modify Nb Seconds (benchmark only) */
@@ -514,7 +508,7 @@ int main(int argc, const char** argv)
}
DISPLAYLEVEL(3, WELCOME_MESSAGE);
- if ((mode == om_compress) || (mode == om_bench)) DISPLAYLEVEL(4, "Blocks size : %i KB\n", blockSize>>10);
+ if ((mode == om_compress) || (mode == om_bench)) DISPLAYLEVEL(4, "Blocks size : %i KB\n", (U32)(blockSize>>10));
if (multiple_inputs) {
input_filename = inFileNames[0];
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 5a366a4..4d076a9 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -134,9 +134,6 @@ static int g_blockIndependence = 1;
static int g_sparseFileSupport = 1;
static int g_contentSizeFlag = 0;
-static const int minBlockSizeID = 4;
-static const int maxBlockSizeID = 7;
-
/**************************************
* Exceptions
@@ -183,10 +180,12 @@ int LZ4IO_setTestMode(int yes)
}
/* blockSizeID : valid values : 4-5-6-7 */
-int LZ4IO_setBlockSizeID(int bsid)
+size_t LZ4IO_setBlockSizeID(unsigned bsid)
{
- static const int blockSizeTable[] = { 64 KB, 256 KB, 1 MB, 4 MB };
- if ((bsid < minBlockSizeID) || (bsid > maxBlockSizeID)) return -1;
+ static const size_t blockSizeTable[] = { 64 KB, 256 KB, 1 MB, 4 MB };
+ static const unsigned minBlockSizeID = 4;
+ static const unsigned maxBlockSizeID = 7;
+ if ((bsid < minBlockSizeID) || (bsid > maxBlockSizeID)) return 0;
g_blockSizeId = bsid;
return blockSizeTable[g_blockSizeId-minBlockSizeID];
}
@@ -777,6 +776,7 @@ static dRess_t LZ4IO_createDResources(void)
ress.dstBuffer = malloc(ress.dstBufferSize);
if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(61, "Allocation error : not enough memory");
+ ress.dstFile = NULL;
return ress;
}
diff --git a/programs/lz4io.h b/programs/lz4io.h
index 315c805..e1ab5f3 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -32,16 +32,20 @@
#ifndef LZ4IO_H_237902873
#define LZ4IO_H_237902873
+/*--- Dependency ---*/
+#include <stddef.h> /* size_t */
+
+
/* ************************************************** */
/* Special input/output values */
/* ************************************************** */
#define NULL_OUTPUT "null"
-static char const stdinmark[] = "stdin";
-static char const stdoutmark[] = "stdout";
+static const char stdinmark[] = "stdin";
+static const char stdoutmark[] = "stdout";
#ifdef _WIN32
-static char const nulmark[] = "nul";
+static const char nulmark[] = "nul";
#else
-static char const nulmark[] = "/dev/null";
+static const char nulmark[] = "/dev/null";
#endif
@@ -69,8 +73,8 @@ int LZ4IO_setOverwrite(int yes);
int LZ4IO_setTestMode(int yes);
/* blockSizeID : valid values : 4-5-6-7
- return : -1 if error, blockSize if OK */
-int LZ4IO_setBlockSizeID(int blockSizeID);
+ return : 0 if error, blockSize if OK */
+size_t LZ4IO_setBlockSizeID(unsigned blockSizeID);
/* Default setting : independent blocks */
typedef enum { LZ4IO_blockLinked=0, LZ4IO_blockIndependent} LZ4IO_blockMode_t;