summaryrefslogtreecommitdiffstats
path: root/programs/datagen.c
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/datagen.c
parent8c32a12f1c50a5561a9efcfe802b5109379a4120 (diff)
downloadlz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.zip
lz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.tar.gz
lz4-d2be69b144d6c5fd9a3dcbc4133e93e710cda998.tar.bz2
fixed minor coverity warnings
Diffstat (limited to 'programs/datagen.c')
-rw-r--r--programs/datagen.c29
1 files changed, 10 insertions, 19 deletions
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;
}