summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2018-01-14 06:58:09 (GMT)
committerYann Collet <cyan@fb.com>2018-01-14 06:58:09 (GMT)
commitcdd0c685e0df961b331ded14d1a01bba250f1c8d (patch)
tree226b50422051b26a6e0af0d8b7dc74a250d8b305 /programs
parent99302c43b4f76f77ef554473da9f8449df8becc2 (diff)
parent75e22d133e0726c6e3d7124eb18edfb9cb09400e (diff)
downloadlz4-cdd0c685e0df961b331ded14d1a01bba250f1c8d.zip
lz4-cdd0c685e0df961b331ded14d1a01bba250f1c8d.tar.gz
lz4-cdd0c685e0df961b331ded14d1a01bba250f1c8d.tar.bz2
Merge branch 'dev' into coverity_scan
Diffstat (limited to 'programs')
-rw-r--r--programs/datagen.c27
-rw-r--r--programs/lz4io.c3
2 files changed, 14 insertions, 16 deletions
diff --git a/programs/datagen.c b/programs/datagen.c
index 7285d69..24a2da2 100644
--- a/programs/datagen.c
+++ b/programs/datagen.c
@@ -31,6 +31,7 @@
#include <stdlib.h> /* malloc */
#include <stdio.h> /* FILE, fwrite */
#include <string.h> /* memcpy */
+#include <assert.h>
/**************************************
@@ -78,7 +79,10 @@ static void RDG_fillLiteralDistrib(litDistribTable lt, double ld)
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;
+ while (u < end) {
+ assert(u<LTSIZE); /* try to ease static analyzer. u < end <= LTSIZE */
+ lt[u++] = character;
+ }
character++;
if (character > lastChar) character = firstChar;
}
@@ -103,13 +107,11 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match
U32* seed = seedPtr;
/* special case */
- while (matchProba >= 1.0)
- {
+ while (matchProba >= 1.0) {
size_t size0 = RDG_rand(seed) & 3;
size0 = (size_t)1 << (16 + size0 * 2);
size0 += RDG_rand(seed) & (size0-1); /* because size0 is power of 2*/
- if (buffSize < pos + size0)
- {
+ if (buffSize < pos + size0) {
memset(buffPtr+pos, 0, buffSize-pos);
return;
}
@@ -125,11 +127,9 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match
}
/* Generate compressible data */
- while (pos < buffSize)
- {
+ while (pos < buffSize) {
/* Select : Literal (char) or Match (within 32K) */
- if (RDG_RAND15BITS < matchProba32)
- {
+ if (RDG_RAND15BITS < matchProba32) {
/* Copy (within 32K) */
size_t match;
size_t d;
@@ -140,9 +140,7 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match
d = pos + length;
if (d > buffSize) d = buffSize;
while (pos < d) buffPtr[pos++] = buffPtr[match++];
- }
- else
- {
+ } else {
/* Literal (noise) */
size_t d;
size_t length = RDG_RANDLENGTH;
@@ -180,12 +178,11 @@ void RDG_genOut(unsigned long long size, double matchProba, double litProba, uns
RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, lt, &seed);
/* Generate compressible data */
- while (total < size)
- {
+ while (total < size) {
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);
+ fwrite(buff, 1, genBlockSize, stdout); /* should check potential write error */
/* update dict */
memcpy(buff, buff + RDG_BLOCKSIZE, RDG_DICTSIZE);
}
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 2cf0c1c..927928a 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -429,7 +429,7 @@ static void* LZ4IO_createDict(const char* dictFilename, size_t *dictSize) {
/* opportunistically seek to the part of the file we care about. If this */
/* fails it's not a problem since we'll just read everything anyways. */
if (strcmp(dictFilename, stdinmark)) {
- UTIL_fseek(dictFile, -LZ4_MAX_DICT_SIZE, SEEK_END);
+ (void)UTIL_fseek(dictFile, -LZ4_MAX_DICT_SIZE, SEEK_END);
}
do {
@@ -459,6 +459,7 @@ static void* LZ4IO_createDict(const char* dictFilename, size_t *dictSize) {
memcpy(dictBuf + circularBufSize - dictStart, circularBuf, dictLen - (circularBufSize - dictStart));
}
+ fclose(dictFile);
free(circularBuf);
return dictBuf;