summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2016-11-15 22:01:37 (GMT)
committerYann Collet <cyan@fb.com>2016-11-15 22:46:57 (GMT)
commitd2be69b144d6c5fd9a3dcbc4133e93e710cda998 (patch)
tree39311a1057f16233f54bccf2f044c6a479c3de74 /programs
parent8c32a12f1c50a5561a9efcfe802b5109379a4120 (diff)
downloadlz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.zip
lz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.tar.gz
lz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.tar.bz2
fixed minor coverity warnings
Diffstat (limited to 'programs')
-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.c7
-rw-r--r--programs/lz4io.h16
6 files changed, 35 insertions, 43 deletions
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..e9a0d4b 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..f34d715 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -183,10 +183,10 @@ 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 };
+ if ((bsid < minBlockSizeID) || (bsid > maxBlockSizeID)) return 0;
g_blockSizeId = bsid;
return blockSizeTable[g_blockSizeId-minBlockSizeID];
}
@@ -777,6 +777,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;