diff --git a/cfg/cairo.cfg b/cfg/cairo.cfg index 85c2a8e0946..e077c2fc40d 100644 --- a/cfg/cairo.cfg +++ b/cfg/cairo.cfg @@ -6,6 +6,7 @@ + diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 20869faf8b4..f15f788dc40 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -2,6 +2,8 @@ + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9e560e101cd..497a40594ae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -113,17 +113,22 @@ if (BUILD_TESTS) else() # TODO: remove missingInclude disabling when it no longer is implied by --enable=information # TODO: add syntax check + # need to suppress unmatchedSuppression in case valueFlowBailout is not reported add_test(NAME cfg-${TEST_NAME} COMMAND $ + --library=${LIBRARY} --check-library --platform=${PLATFORM} - --library=${LIBRARY} --enable=style,information --inconclusive --force --error-exitcode=1 --disable=missingInclude --inline-suppr + --template="{file}:{line}:{severity}:{id}:{message}" + --debug-warnings + --suppress=valueFlowBailout + --suppress=unmatchedSuppression ${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST} ) endif() diff --git a/test/cfg/boost.cpp b/test/cfg/boost.cpp index ee6f77dd854..eba45f8eec1 100644 --- a/test/cfg/boost.cpp +++ b/test/cfg/boost.cpp @@ -83,6 +83,7 @@ void macros() BOOST_PP_REPEAT(5, DECL, int x) BOOST_SCOPED_ENUM_DECLARE_BEGIN(future_errc) { + // cppcheck-suppress valueFlowBailoutIncompleteVar no_state } BOOST_SCOPED_ENUM_DECLARE_END(future_errc) diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index e2ca818f938..9b9ba57d71b 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -316,6 +316,7 @@ void valid_code(int argInt1, va_list valist_arg, const int * parg) if (__alignof__(int) == 4) {} + // cppcheck-suppress valueFlowBailoutIncompleteVar const void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); printf("%p", p_mmap); munmap(p_mmap, 1); diff --git a/test/cfg/googletest.cpp b/test/cfg/googletest.cpp index 9ad2c43da57..cc4c1415ae6 100644 --- a/test/cfg/googletest.cpp +++ b/test/cfg/googletest.cpp @@ -15,12 +15,15 @@ namespace ExampleNamespace { constexpr long long TOLERANCE = 10; // #9397 syntaxError when MATCHER_P is not known + // cppcheck-suppress symbolDatabaseWarning MATCHER_P(ExampleMatcherPTest, expected, "") { + // cppcheck-suppress valueFlowBailoutIncompleteVar return ((arg <= (expected + TOLERANCE)) && (arg >= (expected - TOLERANCE))); } // syntaxError when MATCHER is not known + // cppcheck-suppress symbolDatabaseWarning MATCHER(ExampleMatcherTest, "") { return (arg == TOLERANCE); diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c index 2644f95f0f6..66aa875b229 100644 --- a/test/cfg/gtk.c +++ b/test/cfg/gtk.c @@ -289,6 +289,7 @@ void g_new_if_test() }; const struct a * pNew3; + // cppcheck-suppress valueFlowBailoutIncompleteVar if (pNew3 = g_new(struct a, 6)) { printf("%p", pNew3); } diff --git a/test/cfg/libcurl.c b/test/cfg/libcurl.c index b12157b0f37..354ee549149 100644 --- a/test/cfg/libcurl.c +++ b/test/cfg/libcurl.c @@ -15,6 +15,7 @@ void validCode() CURL *curl = curl_easy_init(); if (curl) { CURLcode res; + // cppcheck-suppress valueFlowBailoutIncompleteVar curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); res = curl_easy_perform(curl); if (res != CURLE_OK) { diff --git a/test/cfg/opencv2.cpp b/test/cfg/opencv2.cpp index 349dc42b2d4..7af2d6b7055 100644 --- a/test/cfg/opencv2.cpp +++ b/test/cfg/opencv2.cpp @@ -14,6 +14,7 @@ void validCode(const char* argStr) { cv::Mat image; + // cppcheck-suppress valueFlowBailoutIncompleteVar image = cv::imread(argStr, cv::IMREAD_COLOR); if (!image.data) { printf("No image data \n"); diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 1e6de23ca83..5d696a5ba04 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -895,6 +895,7 @@ void validCode(va_list valist_arg1, va_list valist_arg2) void *ptr; if (posix_memalign(&ptr, sizeof(void *), sizeof(void *)) == 0) free(ptr); + // cppcheck-suppress valueFlowBailoutIncompleteVar syslog(LOG_ERR, "err %u", 0U); syslog(LOG_WARNING, "warn %d %d", 5, 1); vsyslog(LOG_EMERG, "emerg %d", valist_arg1); diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index 46310e32171..2bef064a983 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -316,7 +316,7 @@ QVector::iterator QVector2() // cppcheck-suppress passedByValue void duplicateExpression_QString_Compare(QString style) //#8723 { - // cppcheck-suppress duplicateExpression + // cppcheck-suppress [duplicateExpression,valueFlowBailoutIncompleteVar] if (style.compare( "x", Qt::CaseInsensitive ) == 0 || style.compare( "x", Qt::CaseInsensitive ) == 0) {} } diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 30563dc9934..310686eabe3 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -2,6 +2,8 @@ set -e # abort on error #set -x # be verbose +# TODO: do not bail out on first error - always run all tests and return error instead + function exit_if_strict { if [ -n "${STRICT}" ] && [ "${STRICT}" -eq 1 ]; then exit 1 @@ -24,7 +26,8 @@ CFG="$DIR"../../cfg/ # TODO: remove missingInclude disabling when it no longer is implied by --enable=information # Cppcheck options -CPPCHECK_OPT='--check-library --platform=unix64 --enable=style,information --inconclusive --force --error-exitcode=-1 --disable=missingInclude --inline-suppr --template="{file}:{line}:{severity}:{id}:{message}"' +# need to suppress unmatchedSuppression in case valueFlowBailout is not reported +CPPCHECK_OPT='--check-library --platform=unix64 --enable=style,information --inconclusive --force --error-exitcode=-1 --disable=missingInclude --inline-suppr --template="{file}:{line}:{severity}:{id}:{message}" --debug-warnings --suppress=valueFlowBailout --suppress=unmatchedSuppression' # Compiler settings CXX=g++ @@ -33,6 +36,7 @@ CC=gcc CC_OPT='-fsyntax-only -w -std=c11' function get_pkg_config_cflags { + # TODO: get rid of the error enabling/disabling? set +e PKGCONFIG=$(pkg-config --cflags "$@") PKGCONFIG_RETURNCODE=$? @@ -65,6 +69,7 @@ function qt_fn { if [ -n "$QTCONFIG" ]; then QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt5Core Qt5Test) [[ $QTBUILDCONFIG =~ (^|[[:space:]])reduce_relocations($|[[:space:]]) ]] && QTCONFIG="${QTCONFIG} -fPIC" + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CXX} ${CXX_OPT} ${QTCONFIG} -x c++ - QTCHECK_RETURNCODE=$? @@ -107,6 +112,7 @@ function windows_fn { # wxwidgets.cpp function wxwidgets_fn { + # TODO: get rid of the error enabling/disabling? set +e WXCONFIG=$(wx-config --cxxflags) WXCONFIG_RETURNCODE=$? @@ -115,6 +121,7 @@ function wxwidgets_fn { echo "wx-config does not work, skipping syntax check for wxWidgets tests." exit_if_strict else + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include \n#include \n#include \n#include \n#if wxVERSION_NUMBER<2950\n#error \"Old version\"\n#endif" | ${CXX} ${CXX_OPT} ${WXCONFIG} -x c++ - WXCHECK_RETURNCODE=$? @@ -137,6 +144,7 @@ function gtk_fn { GTKCONFIG=$(get_pkg_config_cflags gtk+-2.0) fi if [ -n "$GTKCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${GTKCONFIG} -x c - GTKCHECK_RETURNCODE=$? @@ -157,6 +165,7 @@ function gtk_fn { # boost.cpp function boost_fn { + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CXX} ${CXX_OPT} -x c++ - BOOSTCHECK_RETURNCODE=$? @@ -175,6 +184,7 @@ function sqlite3_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then SQLITE3CONFIG=$(get_pkg_config_cflags sqlite3) if [ -n "$SQLITE3CONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${SQLITE3CONFIG} -x c - SQLITE3CHECK_RETURNCODE=$? @@ -206,6 +216,7 @@ function python_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then PYTHON3CONFIG=$(get_pkg_config_cflags python3) if [ -n "$PYTHON3CONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${PYTHON3CONFIG} -x c - PYTHON3CONFIG_RETURNCODE=$? @@ -229,6 +240,7 @@ function lua_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then LUACONFIG=$(get_pkg_config_cflags lua-5.3) if [ -n "$LUACONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${LUACONFIG} -x c - LUACONFIG_RETURNCODE=$? @@ -252,6 +264,7 @@ function libcurl_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then LIBCURLCONFIG=$(get_pkg_config_cflags libcurl) if [ -n "$LIBCURLCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${LIBCURLCONFIG} -x c - LIBCURLCONFIG_RETURNCODE=$? @@ -275,6 +288,7 @@ function cairo_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then CAIROCONFIG=$(get_pkg_config_cflags cairo) if [ -n "$CAIROCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${CAIROCONFIG} -x c - CAIROCONFIG_RETURNCODE=$? @@ -300,6 +314,7 @@ function googletest_fn { # kde.cpp function kde_fn { + # TODO: get rid of the error enabling/disabling? set +e KDECONFIG=$(kde4-config --path include) KDECONFIG_RETURNCODE=$? @@ -313,6 +328,7 @@ function kde_fn { echo "Suitable Qt not present, Qt is necessary for KDE. Skipping syntax check." exit_if_strict else + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include \n" | ${CXX} ${CXX_OPT} -I${KDECONFIG} ${KDEQTCONFIG} -x c++ - KDECHECK_RETURNCODE=$? @@ -333,6 +349,7 @@ function libsigcpp_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then LIBSIGCPPCONFIG=$(get_pkg_config_cflags sigc++-2.0) if [ -n "$LIBSIGCPPCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include \n" | ${CXX} ${CXX_OPT} ${LIBSIGCPPCONFIG} -x c++ - LIBSIGCPPCONFIG_RETURNCODE=$? @@ -356,6 +373,7 @@ function openssl_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then OPENSSLCONFIG=$(get_pkg_config_cflags libssl) if [ -n "$OPENSSLCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include " | ${CC} ${CC_OPT} ${OPENSSLCONFIG} -x c - OPENSSLCONFIG_RETURNCODE=$? @@ -379,6 +397,7 @@ function opencv2_fn { if [ $HAS_PKG_CONFIG -eq 1 ]; then OPENCVCONFIG=$(get_pkg_config_cflags opencv) if [ -n "$OPENCVCONFIG" ]; then + # TODO: get rid of the error enabling/disabling? set +e echo -e "#include \n" | ${CXX} ${CXX_OPT} ${OPENCVCONFIG} -x c++ - OPENCVCONFIG_RETURNCODE=$? diff --git a/test/cfg/sqlite3.c b/test/cfg/sqlite3.c index b493011fc7c..d9480d5ad1d 100644 --- a/test/cfg/sqlite3.c +++ b/test/cfg/sqlite3.c @@ -16,7 +16,7 @@ void validCode() int rc = sqlite3_open("/db", &db); if (rc != SQLITE_OK) { - fprintf(stderr, "Error opening sqlite3 db: %s\n", sqlite3_errmsg(db)); + printf("Error opening sqlite3 db: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); } else { sqlite3_close(db); diff --git a/test/cfg/std.c b/test/cfg/std.c index 4393a17398c..ec5725d09be 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -185,6 +185,7 @@ size_t bufferAccessOutOfBounds_wcsrtombs(char * dest, const wchar_t ** src, size void bufferAccessOutOfBounds(void) { char a[5]; + // cppcheck-suppress valueFlowBailoutIncompleteVar fgets(a,5,stdin); // cppcheck-suppress bufferAccessOutOfBounds fgets(a,6,stdin); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 8a2eafb3921..1762118c716 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -588,6 +588,7 @@ void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n) #ifdef __STDC_LIB_EXT1__ void uninitvar_localtime_s(const std::time_t *restrict time, struct tm *restrict result) { + // cppcheck-suppress valueFlowBailoutIncompleteVar const std::time_t *restrict Time; // TODO cppcheck-suppress uninitvar (void)std::localtime_s(Time, result); @@ -640,6 +641,7 @@ void invalidFunctionArg_std_string_substr(const std::string &str, std::size_t po (void)str.substr(pos,-1); // no warning is expected for (void)str.substr(pos,len); + // cppcheck-suppress valueFlowBailoutIncompleteVar (void)str.substr(pos, std::string::npos); } @@ -4602,8 +4604,10 @@ void stdbind() std::bind(stdbind_helper, 1); // TODO cppcheck-suppress unreadVariable + // cppcheck-suppress autoNoType auto f1 = std::bind(stdbind_helper, _1); // TODO cppcheck-suppress unreadVariable + // cppcheck-suppress autoNoType auto f2 = std::bind(stdbind_helper, 10); } @@ -4778,6 +4782,7 @@ void smartPtr_get() void smartPtr_get2(std::vector>& v) { + // cppcheck-suppress autoNoType for (auto& u : v) { int* p = u.get(); *p = 0; diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 5fbff780aaf..51559ad9a23 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -234,6 +234,7 @@ void validCode() hSemaphore1 = CreateSemaphore(NULL, 0, 1, NULL); CloseHandle(hSemaphore1); HANDLE hSemaphore2; + // cppcheck-suppress valueFlowBailoutIncompleteVar hSemaphore2 = CreateSemaphoreEx(NULL, 0, 1, NULL, 0, SEMAPHORE_ALL_ACCESS); CloseHandle(hSemaphore2); HANDLE hSemaphore3;