]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed minor warnings
authorYann Collet <cyan@fb.com>
Sat, 25 Aug 2018 04:38:09 +0000 (21:38 -0700)
committerYann Collet <cyan@fb.com>
Sat, 25 Aug 2018 06:25:35 +0000 (23:25 -0700)
valgrind: memory leak of a few bytes in fullbench
static analyzer: uninitialized data passed as result

programs/bench.c
tests/fullbench.c
tests/paramgrill.c

index 65658785d0641d870d7fa06c9aff45830928ff6a..1e4aa4d02f6f94d1a18a3be37f421d1cf97fff64 100644 (file)
@@ -984,7 +984,7 @@ BMK_benchOutcome_t BMK_benchFilesAdvanced(
     void* dictBuffer = NULL;
     size_t dictBufferSize = 0;
     size_t* fileSizes = NULL;
-    BMK_benchOutcome_t res = BMK_benchOutcome_error();  /* error by default */
+    BMK_benchOutcome_t res;
     U64 const totalSizeToLoad = UTIL_getTotalFileSize(fileNamesTable, nbFiles);
 
     if (!nbFiles) {
index e545e17bdac6ba8baa3514560df33bcb157a7170..36ac23ecc6f297627160bcab0f76cb359145e277 100644 (file)
@@ -338,9 +338,9 @@ static size_t benchMem(U32 benchNb,
                        const void* src, size_t srcSize,
                        int cLevel, ZSTD_compressionParameters cparams)
 {
-    BYTE*  dstBuff;
     size_t dstBuffSize = ZSTD_compressBound(srcSize);
-    void*  buff1;
+    BYTE*  dstBuff;
+    void*  dstBuff2;
     void*  buff2;
     const char* benchName;
     BMK_benchFn_t benchFunction;
@@ -396,13 +396,13 @@ static size_t benchMem(U32 benchNb,
 
     /* Allocation */
     dstBuff = (BYTE*)malloc(dstBuffSize);
-    buff2 = malloc(dstBuffSize);
-    if ((!dstBuff) || (!buff2)) {
+    dstBuff2 = malloc(dstBuffSize);
+    if ((!dstBuff) || (!dstBuff2)) {
         DISPLAY("\nError: not enough memory!\n");
-        free(dstBuff); free(buff2);
+        free(dstBuff); free(dstBuff2);
         return 12;
     }
-    buff1 = buff2;
+    buff2 = dstBuff2;
     if (g_zcc==NULL) g_zcc = ZSTD_createCCtx();
     if (g_zdc==NULL) g_zdc = ZSTD_createDCtx();
     if (g_cstream==NULL) g_cstream = ZSTD_createCStream();
@@ -545,12 +545,14 @@ static size_t benchMem(U32 benchNb,
             }
 
             if ( BMK_isCompleted_runOutcome(bOutcome) ) break;
-    }   }
+        }
+        BMK_freeTimedFnState(tfs);
+    }
     DISPLAY("\n");
 
 _cleanOut:
-    free(buff1);
     free(dstBuff);
+    free(dstBuff2);
     ZSTD_freeCCtx(g_zcc); g_zcc=NULL;
     ZSTD_freeDCtx(g_zdc); g_zdc=NULL;
     ZSTD_freeCStream(g_cstream); g_cstream=NULL;
@@ -654,7 +656,7 @@ static int benchFiles(U32 benchNb,
 
 #define ERROR_OUT(msg) { DISPLAY("%s \n", msg); exit(1); }
 
- static unsigned readU32FromChar(const char** stringPtr)
+static unsigned readU32FromChar(const char** stringPtr)
 {
     const char errorMsg[] = "error: numeric value too large";
     unsigned result = 0;
index 869bacd98dca0028a58da56449ce9cb8646d44d1..d9e08d0c77494ec297e58b244b050572863ab81c 100644 (file)
@@ -1451,6 +1451,7 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
 
             if (!BMK_isSuccessful_runOutcome(cOutcome)) {
                 BMK_benchOutcome_t bOut;
+                memset(&bOut, 0, sizeof(bOut));
                 bOut.tag = 1;   /* should rather be a function or a constant */
                 BMK_freeTimedFnState(timeStateCompress);
                 BMK_freeTimedFnState(timeStateDecompress);
@@ -1474,6 +1475,7 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
 
             if (!BMK_isSuccessful_runOutcome(dOutcome)) {
                 BMK_benchOutcome_t bOut;
+                memset(&bOut, 0, sizeof(bOut));
                 bOut.tag = 1;   /* should rather be a function or a constant */
                 BMK_freeTimedFnState(timeStateCompress);
                 BMK_freeTimedFnState(timeStateDecompress);
@@ -1506,8 +1508,10 @@ static int BMK_benchParam ( BMK_benchResult_t* resultPtr,
     BMK_benchOutcome_t const outcome = BMK_benchMemInvertible(buf, ctx,
                                                         BASE_CLEVEL, &cParams,
                                                         BMK_both, 3);
-    *resultPtr = BMK_extract_benchResult(outcome);  /* note : will abort() if there is an error in BMK_benchMemInvertible() */
-    return !BMK_isSuccessful_benchOutcome(outcome);
+    int const success = BMK_isSuccessful_benchOutcome(outcome);
+    if (!success) return 1;
+    *resultPtr = BMK_extract_benchResult(outcome);
+    return 0;
 }