diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index fafd0fb53..1d280d1db 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -314,7 +314,7 @@ jobs: if: contains(matrix.os, 'macos') run: | # pcre was removed from runner images in November 2022 - brew install coreutils python3 pcre + brew install coreutils python3 pcre gnu-sed - name: Install missing Python packages run: | @@ -335,9 +335,8 @@ jobs: run: | make -j$(nproc) check HAVE_RULES=yes - # the script uses sed parameters not supported by MacOS + # requires "gnu-sed" installed on macos - name: Run extra tests - if: contains(matrix.os, 'ubuntu') run: | tools/generate_and_run_more_tests.sh @@ -351,9 +350,8 @@ jobs: cd 'cpp check/test/cli' python3 -m pytest test-*.py - # fails on macos since some includes (e.g. sys/epoll.h) are not available - name: Run cfg tests - if: contains(matrix.os, 'ubuntu') && matrix.os != 'ubuntu-22.04' + if: matrix.os != 'ubuntu-22.04' run: | make -j$(nproc) checkcfg @@ -364,9 +362,7 @@ jobs: env: STRICT: 1 - # it seems macos has no "wc" command - name: Run showtimetop5 tests - if: contains(matrix.os, 'ubuntu') run: | ./tools/test_showtimetop5.sh diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index 4ec584486..279c33086 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -19,14 +19,17 @@ #include #include #include -#ifndef __CYGWIN__ +#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__)) #include #endif #include +#ifdef __gnu_linux__ #include +#endif #include #include +#ifdef __gnu_linux__ void unreachableCode_error(void) // #11197 { error(1, 0, ""); // will call exit() if the first parameter is non-zero @@ -34,6 +37,7 @@ void unreachableCode_error(void) // #11197 // TODO cppcheck-suppress unreachableCode int i; } +#endif int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret, char* buf, size_t buflen, struct hostent** result, int* h_errnop) { @@ -431,7 +435,7 @@ void leakReturnValNotUsed() return; } -#ifndef __CYGWIN__ +#if !defined(__CYGWIN__) && !(defined(__APPLE__) && defined(__MACH__)) int nullPointer_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { // no warning is expected diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 2544c8a0a..1dd67da21 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -7,6 +7,8 @@ // No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 // +#define _BSD_SOURCE + #include #include // <- FILE #include @@ -19,7 +21,7 @@ #include #include #include -// unavailable on some linux systems #include +// #include // unavailable on some linux systems #include #include #include @@ -28,20 +30,23 @@ #include #include #include +#if !(defined(__APPLE__) && defined(__MACH__)) #include -#define _XOPEN_SOURCE +#endif #include #include #include #include #include +#if !(defined(__APPLE__) && defined(__MACH__)) void nullPointer_mq_timedsend(mqd_t mqdes, const char* msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec* abs_timeout) { // cppcheck-suppress nullPointer (void) mq_timedsend(mqdes, NULL, msg_len, msg_prio, abs_timeout); // cppcheck-suppress nullPointer (void) mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL); } +#endif #if __TRACE_H__ // @@ -143,6 +148,7 @@ int nullPointer_getopt(int argc, char* const argv[], const char* optstring) return getopt(argc, argv, optstring); } +#if !(defined(__APPLE__) && defined(__MACH__)) int invalidFunctionArgStr_mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio) { // No warning is expected for: @@ -150,6 +156,7 @@ int invalidFunctionArgStr_mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_l (void) mq_send(mqdes, &msg, 1, 0); return mq_send(mqdes, msg_ptr, msg_len, 0); } +#endif void invalidFunctionArgStr_mbsnrtowcs(void) { @@ -492,6 +499,7 @@ int nullPointer_aio_suspend(const struct aiocb *const aiocb_list[], int nitems, return aio_suspend(aiocb_list, nitems, timeout); } +#ifdef __linux__ // Note: Since glibc 2.28, this function symbol is no longer available to newly linked applications. void invalidFunctionArg_llseek(int fd, loff_t offset, int origin) { @@ -522,6 +530,7 @@ void invalidFunctionArg_llseek(int fd, loff_t offset, int origin) // cppcheck-suppress llseekCalled (void)llseek(fd, offset, SEEK_END); } +#endif void invalidFunctionArg_lseek64(int fd, off_t offset, int origin) { diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 46833b80c..0b40098d5 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -27,9 +27,9 @@ CPPCHECK_OPT='--check-library --platform=unix64 --enable=style,information --inc # Compiler settings CXX=g++ -CXX_OPT='-fsyntax-only -std=c++2a -Wno-format -Wno-format-security -Wno-deprecated-declarations' +CXX_OPT='-fsyntax-only -w -std=c++2a' CC=gcc -CC_OPT='-Wno-format -Wno-stringop-overread -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only' +CC_OPT='-fsyntax-only -w -std=c11' function get_pkg_config_cflags { set +e @@ -194,7 +194,10 @@ function sqlite3_fn { # openmp.c function openmp_fn { - ${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c + # MacOS compiler has no OpenMP by default + if ! command -v sw_vers; then + ${CC} ${CC_OPT} -fopenmp ${DIR}openmp.c + fi } # python.c diff --git a/test/cfg/std.c b/test/cfg/std.c index a3146ec75..78442a8be 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -28,6 +28,8 @@ #endif #include #include +#include +#include size_t invalidFunctionArgStr_wcslen(void) { diff --git a/tools/run_more_tests.sh b/tools/run_more_tests.sh index 9bc329527..86c675f90 100755 --- a/tools/run_more_tests.sh +++ b/tools/run_more_tests.sh @@ -1,6 +1,9 @@ #!/bin/bash # Script Used by generate_and_run_more_tests.sh +# "gsed" is a GNU compatible version of "sed" on MacOS +SED_CMD=$(command -v gsed || command -v sed) + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" set -e @@ -19,85 +22,85 @@ $CPPCHECK -q --template=cppcheck1 . 2> 1.txt # (!x) => (x==0) -sed -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x==0) => (0==x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0==x) => (!x) -sed -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # if (x) => (x!=0) -sed -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp +$SED_CMD -ri 's/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # while (x) => (x!=0) -sed -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp +$SED_CMD -ri 's/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x!=0) => (0!=x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0!=x) => (x) -sed -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x < 0) => (0 > x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x <= 0) => (0 >= x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x > 0) => (0 < x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x >= 0) => (0 <= x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x == 123) => (123 == x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (x != 123) => (123 != x) -sed -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0 < x) => (x > 0) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0 <= x) => (x >= 0) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0 > x) => (x < 0) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (0 >= x) => (x <= 0) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (123 == x) => (x == 123) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt # (123 != x) => (x <= 123) -sed -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp +$SED_CMD -ri 's/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' *.cpp $CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt diff --git a/tools/test_showtimetop5.sh b/tools/test_showtimetop5.sh index 99677225c..81315dd27 100755 --- a/tools/test_showtimetop5.sh +++ b/tools/test_showtimetop5.sh @@ -1,6 +1,8 @@ #!/bin/bash +# "gwc" is a GNU compatible of "wc" on MacOS +WC_CMD=$(command -v gwc || command -v wc) output=$(./cppcheck --showtime=top5 cli/cmdlineparser.h --language=c++ --quiet) echo "$output" -if [[ "$(echo "$output" | wc -l)" != 7 ]] ; then +if [[ "$(echo "$output" | $WC_CMD -l)" != 7 ]] ; then false fi