added cppcheck
authorYann Collet <cyan@fb.com>
Tue, 18 Sep 2018 23:52:02 +0000 (16:52 -0700)
committerYann Collet <cyan@fb.com>
Tue, 18 Sep 2018 23:52:02 +0000 (16:52 -0700)
as Makefile target and Travis CI test.

Fixed last cppcheck warnings in tests and examples

.travis.yml
Makefile
contrib/gen_manual/gen_manual.cpp
tests/frametest.c
tests/fullbench.c

index de6875b..5b0c6ca 100644 (file)
@@ -129,13 +129,14 @@ matrix:
             - qemu-user-static
             - gcc-powerpc-linux-gnu
 
-    - env: Ubu=14.04 Cmd='make staticAnalyze' COMPILER=clang
+    - env: Ubu=14.04 Cmd='make staticAnalyze && make cppcheck' COMPILER=clang
       dist: trusty
       sudo: required
       addons:
         apt:
           packages:
             - clang
+            - cppcheck
 
     - env: Ubu=14.04 Cmd='make clean all CC=gcc-4.4 MOREFLAGS=-Werror && make clean && CFLAGS=-fPIC LDFLAGS="-pie -fPIE -D_FORTIFY_SOURCE=2" make -C programs' COMPILER=gcc-4.4
       dist: trusty
index e8e6473..2f8b85c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -148,9 +148,14 @@ usan: clean
 usan32: clean
        CFLAGS="-m32 -O3 -g -fsanitize=undefined" $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
 
+.PHONY: staticAnalyze
 staticAnalyze: clean
        CFLAGS=-g scan-build --status-bugs -v $(MAKE) all
 
+.PHONY: cppcheck
+cppcheck:
+       cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
+
 platformTest: clean
        @echo "\n ---- test lz4 with $(CC) compiler ----"
        @$(CC) -v
index e12273f..bedef94 100644 (file)
@@ -180,9 +180,9 @@ int main(int argc, char *argv[]) {
         if (!comments.empty())
             comments[comments.size()-1] = comments[comments.size()-1].substr(0, comments[comments.size()-1].find("*/"));
         for (l=0; l<comments.size(); l++) {
-            if (comments[l].find(" *") == 0)
+            if (comments[l].compare(0, 2, " *") == 0)
                 comments[l] = comments[l].substr(2);
-            else if (comments[l].find("  *") == 0)
+            else if (comments[l].compare(0, 3, "  *") == 0)
                 comments[l] = comments[l].substr(3);
             trim(comments[l], "*-=");
         }
index 4efeb6f..5714732 100644 (file)
@@ -520,7 +520,7 @@ int basicTests(U32 seed, double compressibility)
         LZ4F_CDict* const cdict = LZ4F_createCDict(CNBuffer, dictSize);
         if (cdict == NULL) goto _output_error;
         CHECK( LZ4F_createCompressionContext(&cctx, LZ4F_VERSION) );
-        
+
         DISPLAYLEVEL(3, "LZ4F_compressFrame_usingCDict, with NULL dict : ");
         CHECK_V(cSizeNoDict,
                 LZ4F_compressFrame_usingCDict(cctx, compressedBuffer, dstCapacity,
@@ -840,7 +840,7 @@ int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, double compressi
                 size_t const iSize = MIN(sampleMax, (size_t)(iend-ip));
                 size_t const oSize = LZ4F_compressBound(iSize, prefsPtr);
                 cOptions.stableSrc = ((FUZ_rand(&randState) & 3) == 1);
-                DISPLAYLEVEL(6, "Sending %zi bytes to compress (stableSrc:%u) \n",
+                DISPLAYLEVEL(6, "Sending %zu bytes to compress (stableSrc:%u) \n",
                                 iSize, cOptions.stableSrc);
 
                 result = LZ4F_compressUpdate(cCtx, op, oSize, ip, iSize, &cOptions);
index fd1202d..4b4e921 100644 (file)
@@ -367,7 +367,6 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
       size_t readSize;
       int compressedBuffSize;
       U32 crcOriginal;
-      size_t errorCode;
 
       /* Check file existence */
       if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }
@@ -561,7 +560,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
             case 8: decompressionFunction = local_LZ4_decompress_safe_forceExtDict; dName = "LZ4_decompress_safe_forceExtDict"; break;
 #endif
             case 9: decompressionFunction = local_LZ4F_decompress; dName = "LZ4F_decompress";
-                    errorCode = LZ4F_compressFrame(compressed_buff, compressedBuffSize, orig_buff, benchedSize, NULL);
+                {   size_t const errorCode = LZ4F_compressFrame(compressed_buff, compressedBuffSize, orig_buff, benchedSize, NULL);
                     if (LZ4F_isError(errorCode)) {
                         DISPLAY("Error while preparing compressed frame\n");
                         free(orig_buff);
@@ -573,6 +572,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
                     chunkP[0].compressedSize = (int)errorCode;
                     nbChunks = 1;
                     break;
+                }
             default :
                 continue;   /* skip if unknown ID */
             }