]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed minor visual analyzer warning 38/head
authorYann Collet <yann.collet.73@gmail.com>
Wed, 8 Jul 2015 01:26:17 +0000 (17:26 -0800)
committerYann Collet <yann.collet.73@gmail.com>
Wed, 8 Jul 2015 01:26:17 +0000 (17:26 -0800)
programs/Makefile
programs/datagen.c
programs/datagen.h

index 640446225b0345288a024ec7738dd1c7a2dd134a..20205b90a2bca7d4975f792200d569e147423464 100644 (file)
@@ -59,7 +59,7 @@ endif
 
 default: zstd
 
-all: zstd zstd32 fullbench fullbench32 fuzzer fuzzer32
+all: zstd zstd32 fullbench fullbench32 fuzzer fuzzer32 datagen
 
 zstd: $(ZSTDDIR)/zstd.c xxhash.c bench.c fileio.c zstdcli.c
        $(CC)      $(FLAGS) $^ -o $@$(EXT)
index 50daaa0772dab3c1ab1a715b51d5e66663a80654..fa0e62a1fafed886e2617ad960085957c99a789b 100644 (file)
@@ -130,7 +130,6 @@ static BYTE RDG_genChar(U32* seed, const litDistribTable lt)
 }
 
 
-#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, litDistribTable lt, unsigned* seedPtr)
@@ -140,7 +139,7 @@ void RDG_genBlock(void* buffer, size_t buffSize, size_t prefixSize, double match
     size_t pos = prefixSize;
     U32* seed = seedPtr;
 
-    /* special case */
+    /* special case : sparse content */
     while (matchProba >= 1.0)
     {
         size_t size0 = RDG_rand(seed) & 3;
@@ -154,6 +153,7 @@ 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, lt);
+        return;
     }
 
     /* init */
@@ -198,20 +198,22 @@ void RDG_genBuffer(void* buffer, size_t size, double matchProba, double litProba
 }
 
 
+#define RDG_DICTSIZE  (32 KB)
 #define RDG_BLOCKSIZE (128 KB)
 void RDG_genOut(unsigned long long size, double matchProba, double litProba, unsigned seed)
 {
-    BYTE buff[RDG_DICTSIZE + RDG_BLOCKSIZE];
+    BYTE* buff = (BYTE*)malloc(RDG_DICTSIZE + RDG_BLOCKSIZE);
     U64 total = 0;
     size_t genBlockSize = RDG_BLOCKSIZE;
     litDistribTable lt;
 
     /* init */
+    if (buff==NULL) { fprintf(stdout, "not enough memory\n"); exit(1); }
     if (litProba==0.0) litProba = matchProba / 4.5;
     RDG_fillLiteralDistrib(lt, litProba);
     SET_BINARY_MODE(stdout);
 
-    /* Generate dict */
+    /* Generate initial dict */
     RDG_genBlock(buff, RDG_DICTSIZE, 0, matchProba, lt, &seed);
 
     /* Generate compressible data */
@@ -224,4 +226,7 @@ void RDG_genOut(unsigned long long size, double matchProba, double litProba, uns
         /* update dict */
         memcpy(buff, buff + RDG_BLOCKSIZE, RDG_DICTSIZE);
     }
+
+    // cleanup
+    free(buff);
 }
index 631d1463db1aeacc6b7b806bdde5b51a3271697a..89482dc2c4232762e1da9dddbb55da2e995a2408 100644 (file)
 
 void RDG_genOut(unsigned long long size, double matchProba, double litProba, unsigned seed);
 void RDG_genBuffer(void* buffer, size_t size, double matchProba, double litProba, unsigned seed);
-/* RDG_genOut
-   Generate 'size' bytes of compressible data into stdout.
+/* RDG_genBuffer
+   Generate 'size' bytes of compressible data into 'buffer'.
    Compressibility can be controlled using 'matchProba'.
-   'LitProba' is optional, and affect variability of bytes. If litProba==0.0, default value is used.
-   Generated data can be selected using 'seed'.
+   'LitProba' is optional, and affect variability of individual bytes. If litProba==0.0, default value is used.
+   Generated data pattern can be modified using different 'seed'.
    If (matchProba, litProba and seed) are equal, the function always generate the same content.
 
-   RDG_genBuffer
-   Same as RDG_genOut, but generate data into provided buffer
+   RDG_genOut
+   Same as RDG_genBuffer, but generate data towards stdout
 */