From a57c68f55ee5e3be19f04f6b3723f1d0230ed6e0 Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Fri, 19 Jun 2020 11:06:41 +0100 Subject: [PATCH 1/2] Implement changes to support cppcheck 2.x --- .travis.yml | 11 ++++---- scripts/install_cppcheck.sh | 54 ++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 255612bf..963f0f38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ addons: # This is required to use a version of cppcheck other than that # suplied with the operating system cppcheck_defs: &cppcheck_defs - - CPPCHECK_VER=1.90 + - CPPCHECK_VER=2.1 - CPPCHECK_REPO=https://github.com/danmar/cppcheck.git min_amd64_deps: &min_amd64_deps @@ -92,10 +92,11 @@ cppcheck_conf: &cppcheck_conf env: - *cppcheck_defs -# addons: -# apt: -# packages: -# - cppcheck + addons: + apt: + packages: + - libz3-dev + - z3 script: - ./bootstrap diff --git a/scripts/install_cppcheck.sh b/scripts/install_cppcheck.sh index 87f436fb..ef6eecd4 100755 --- a/scripts/install_cppcheck.sh +++ b/scripts/install_cppcheck.sh @@ -48,6 +48,45 @@ call_make() return $status } + +# ---------------------------------------------------------------------------- +# C R E A T E Z 3 V E R S I O N H +# +# Older versions of libz3-dev do not come packaged with z3_version.h. This +# function uses the z3 command to create a copy of this file in the +# cppcheck i#externalsi# directory. +# ---------------------------------------------------------------------------- +create_z3_version_h() +{ + set -- `z3 --version` + if [ $# != 3 -o "$1/$2" != Z3/version ]; then + echo "** Unexpected output from z3 command '$*'" >&2 + false + else + z3ver=$3 ; # e.g. 4.4.3 + set -- `echo $z3ver | tr '.' ' '` + if [ $# != 3 ]; then + echo "** Unable to determine Z3 version from '$z3ver'" >&2 + false + else + { + echo "#ifndef Z3_MAJOR_VERSION" + echo "#define Z3_MAJOR_VERSION $1" + echo "#endif" + echo + echo "#ifndef Z3_MINOR_VERSION" + echo "#define Z3_MINOR_VERSION $2" + echo "#endif" + echo + echo "#ifndef Z3_BUILD_NUMBER" + echo "#define Z3_BUILD_NUMBER $3" + echo "#endif" + } >externals/z3_version.h + echo " - Created z3_version.h for $1.$2.$3" + fi + fi +} + # ---------------------------------------------------------------------------- # M A I N # ---------------------------------------------------------------------------- @@ -78,14 +117,23 @@ fi # Put everything in this directory FILESDIR=$INSTALL_ROOT/$CPPCHECK_VER - # CFGDIR is needed for cppcheck before 1.86 - make_args="FILESDIR=$FILESDIR PREFIX=$FILESDIR CFGDIR=$FILESDIR" - # See https://stackoverflow.com/questions/ # 791959/download-a-specific-tag-with-git git clone -b $CPPCHECK_VER --depth 1 $REPO_URL $workdir cd $workdir + + case "$CPPCHECK_VER" in + 1.*) + # CFGDIR is needed for cppcheck before 1.86 + make_args="FILESDIR=$FILESDIR PREFIX=$FILESDIR CFGDIR=$FILESDIR" + ;; + *) make_args="FILESDIR=$FILESDIR PREFIX=$FILESDIR USE_Z3=yes" + if [ ! -f /usr/include/z3_version.h ]; then + create_z3_version_h + fi + esac + echo "Making cppcheck..." # CFGDIR is needed for cppcheck before 1.86 call_make $make_args From 27653f97f219441466d3e99a1b5f0af8a2f5b08e Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Fri, 19 Jun 2020 11:07:23 +0100 Subject: [PATCH 2/2] Code changes for cppcheck 2.1 warnings --- common/log.c | 1 + common/os_calls.c | 6 ++++++ common/pixman-region.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/common/log.c b/common/log.c index 50a44e9e..4a0bd2f3 100644 --- a/common/log.c +++ b/common/log.c @@ -569,6 +569,7 @@ log_message(const enum logLevels lvl, const char *msg, ...) if (len > LOG_BUFFER_SIZE) { log_message(LOG_LEVEL_WARNING, "next message will be truncated"); + len = LOG_BUFFER_SIZE; } /* forcing the end of message string */ diff --git a/common/os_calls.c b/common/os_calls.c index 88b96e61..463af84c 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -2896,6 +2896,12 @@ g_strtrim(char *str, int trim_flags) text = (wchar_t *)malloc(len * sizeof(wchar_t) + 8); text1 = (wchar_t *)malloc(len * sizeof(wchar_t) + 8); + if (text == NULL || text1 == NULL) + { + free(text); + free(text1); + return 1; + } text1_index = 0; mbstowcs(text, str, len + 1); diff --git a/common/pixman-region.c b/common/pixman-region.c index eb3fd179..f974eb28 100644 --- a/common/pixman-region.c +++ b/common/pixman-region.c @@ -83,6 +83,12 @@ #define GOOD_RECT(rect) ((rect)->x1 < (rect)->x2 && (rect)->y1 < (rect)->y2) #define BAD_RECT(rect) ((rect)->x1 > (rect)->x2 || (rect)->y1 > (rect)->y2) +/* This file is included by pixman-region16.c which defines PREFIX(x). + * This check allows cppcheck 2.x to scan this file separately */ +#ifndef PREFIX +#define PREFIX(x) pixman_region##x +#endif + #ifdef XRDP_DEBUG #define GOOD(reg) \