From 9e1420309c075ff1cc74514e39d0cf6da1e4e19c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 6 Feb 2020 22:18:23 +0100 Subject: Travis: update CLang Static Analyzer to CLang 9 Enable optional checkers Fix two false positives --- src/init.cpp | 2 +- src/param.cpp | 2 +- src/proj_internal.h | 2 +- travis/csa/before_install.sh | 6 +++--- travis/csa/install.sh | 29 ++++++++++++++++++++++++++--- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 9c7b7b19..a25d1ccd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -239,7 +239,7 @@ Expand key from buffer or (if not in buffer) from init file char initname[5]; int exists; - memcpy(initname, xkey, 4); + strncpy(initname, xkey, 4); initname[4] = 0; if( strncmp(xkey, "epsg:", 5) == 0 ) { diff --git a/src/param.cpp b/src/param.cpp index 182c40b0..289faca3 100644 --- a/src/param.cpp +++ b/src/param.cpp @@ -85,7 +85,7 @@ paralist *pj_mkparam_ws (const char *str, const char **next_str) { newitem = (paralist *) pj_calloc (1, sizeof(paralist) + len + 1); if (nullptr==newitem) return nullptr; - memmove(newitem->param, str, len); + memcpy(newitem->param, str, len); unquote_string(newitem->param); newitem->used = 0; diff --git a/src/proj_internal.h b/src/proj_internal.h index 7a777027..557c61cb 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -560,7 +560,7 @@ struct PJconsts { struct ARG_list { paralist *next; char used; -#if defined(__GNUC__) && __GNUC__ >= 8 +#if (defined(__GNUC__) && __GNUC__ >= 8) || (defined(__clang__) && __clang_major__ >= 9) char param[]; /* variable-length member */ /* Safer to use [] for gcc 8. See https://github.com/OSGeo/proj.4/pull/1087 */ /* and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914 */ diff --git a/travis/csa/before_install.sh b/travis/csa/before_install.sh index dcb7733b..0ebc94fb 100755 --- a/travis/csa/before_install.sh +++ b/travis/csa/before_install.sh @@ -7,7 +7,7 @@ set -e sudo apt-get install -qq sqlite3 libsqlite3-dev libtiff-dev libcurl4-openssl-dev -CLANG_LLVM=clang+llvm-6.0.0-x86_64-linux-gnu-ubuntu-16.04 -wget http://releases.llvm.org/6.0.0/$CLANG_LLVM.tar.xz +CLANG_LLVM=clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-16.04 +wget http://releases.llvm.org/9.0.0/$CLANG_LLVM.tar.xz tar xJf $CLANG_LLVM.tar.xz -mv $CLANG_LLVM clang+llvm-6 +mv $CLANG_LLVM clang+llvm-9 diff --git a/travis/csa/install.sh b/travis/csa/install.sh index 334389ee..349afcb1 100755 --- a/travis/csa/install.sh +++ b/travis/csa/install.sh @@ -5,7 +5,30 @@ set -e # prepare build files ./autogen.sh -CXXFLAGS="-std=c++11" ./clang+llvm-6/bin/scan-build -o scanbuildoutput -plist -v ./configure -./clang+llvm-6/bin/scan-build -o scanbuildoutput -plist -v make -j2 +export PATH=$PWD/clang+llvm-9/bin:$PATH +CXXFLAGS="-std=c++11" scan-build -o scanbuildoutput -plist -v ./configure +rm -rf scanbuildoutput +TOPDIR=$PWD +scan-build -o $TOPDIR/scanbuildoutput -sarif -v -enable-checker alpha.unix.cstring.OutOfBounds,alpha.unix.cstring.BufferOverlap,optin.cplusplus.VirtualCall,optin.cplusplus.UninitializedObject make -j2 -if grep -r "\.c" scanbuildoutput | grep "" | grep -v -e "" -e _generated_parser; then echo "error" && /bin/false; else echo "ok"; fi +sudo apt-get install jq + +rm -f filtered_scanbuild.txt +files=$(find scanbuildoutput -name "*.sarif") +for f in $files; do + jq '.runs[].results[] | (if .locations[].physicalLocation.fileLocation.uri | (contains("_generated_parser") ) then empty else { "uri": .locations[].physicalLocation.fileLocation.uri, "msg": .message.text, "location": .codeFlows[-1].threadFlows[-1].locations[-1] } end)' < $f > tmp.txt + if [ -s tmp.txt ]; then + echo "Errors from $f: " + cat $f + echo "" + cat tmp.txt >> filtered_scanbuild.txt + fi +done +if [ -s filtered_scanbuild.txt ]; then + echo "" + echo "" + echo "========================" + echo "Summary of errors found:" + cat filtered_scanbuild.txt + /bin/false +fi -- cgit v1.2.3 From c8f8a5a6c522fcd18b2ca42d4345bc9be115abd3 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 6 Feb 2020 23:33:38 +0100 Subject: Fix cppcheck warnings and make it work with latest cppcheck 1.90 --- scripts/cppcheck.sh | 4 ++++ src/apps/projsync.cpp | 2 +- src/projections/isea.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index f42d5f6d..1cfd61b5 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -43,6 +43,10 @@ grep -v "unmatchedSuppression" ${LOG_FILE} \ | grep -v "passedByValue,Function parameter 'xyz' should be passed by const reference" \ | grep -v "passedByValue,Function parameter 'in' should be passed by const reference" \ | grep -v "knownConditionTrueFalse,Condition '!allowEmptyIntersection' is always false" \ + | grep -v -e "unitconvert.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \ + | grep -v -e "helmert.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \ + | grep -v -e "molodensky.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \ + | grep -v -e "vgridshift.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \ > ${LOG_FILE}.tmp mv ${LOG_FILE}.tmp ${LOG_FILE} diff --git a/src/apps/projsync.cpp b/src/apps/projsync.cpp index 3fab38e1..40848f51 100644 --- a/src/apps/projsync.cpp +++ b/src/apps/projsync.cpp @@ -52,7 +52,7 @@ class ParsingException : public std::exception { std::string msg_; public: - ParsingException(const char *msg) : msg_(msg) {} + explicit ParsingException(const char *msg) : msg_(msg) {} const char *what() const noexcept override { return msg_.c_str(); } }; } diff --git a/src/projections/isea.cpp b/src/projections/isea.cpp index 351739d4..801f2b82 100644 --- a/src/projections/isea.cpp +++ b/src/projections/isea.cpp @@ -733,7 +733,7 @@ static int isea_dddi_ap3odd(struct isea_dgg *g, int quadz, struct isea_pt *pt, quadz += 5; d = 0; } - } else if (quadz >= 6) { + } else /* if (quadz >= 6) */ { if (i == 0 && d == maxcoord) { /* south pole */ quadz = 11; @@ -812,7 +812,7 @@ static int isea_dddi(struct isea_dgg *g, int quadz, struct isea_pt *pt, h.y = -h.z; h.x = 0; } - } else if (quadz >= 6) { + } else /* if (quadz >= 6) */ { if (h.z == 0 && h.x == sidelength) { /* south pole */ quadz = 11; -- cgit v1.2.3