diff --git a/cfg/std.cfg b/cfg/std.cfg index d0ff90e10..112ff4f3c 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -4594,7 +4594,7 @@ - + false diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index cbfa376ae..578e69a75 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -9,23 +9,30 @@ else # assume we are in repo root DIR=./test/cfg/ fi +# Cppcheck options +CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr' + # Compiler settings CXX=g++ +CXX_OPT='-fsyntax-only' CC=gcc CC_OPT='-Wno-nonnull -fsyntax-only' # posix.c ${CC} ${CC_OPT} ${DIR}posix.c -${CPPCHECK} --check-library --library=posix --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr ${DIR}posix.c +${CPPCHECK} ${CPPCHECK_OPT} --library=posix ${DIR}posix.c # gnu.c ${CC} ${CC_OPT} -D_GNU_SOURCE ${DIR}gnu.c -${CPPCHECK} --check-library --library=gnu --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr ${DIR}gnu.c - -# windows.cpp -#${CXX} -fsyntax-only ${DIR}windows.cpp -${CPPCHECK} --check-library --library=windows --enable=information --enable=style --error-exitcode=1 --inline-suppr ${DIR}windows.cpp +${CPPCHECK} ${CPPCHECK_OPT} --library=gnu ${DIR}gnu.c # std.c ${CC} ${CC_OPT} ${DIR}std.c -${CPPCHECK} --check-library --enable=information --error-exitcode=1 --enable=style --suppress=missingIncludeSystem --inline-suppr ${DIR}std.c +${CPPCHECK} ${CPPCHECK_OPT} ${DIR}std.c +${CXX} ${CXX_OPT} ${DIR}std.cpp +${CPPCHECK} ${CPPCHECK_OPT} ${DIR}std.cpp + +# windows.cpp +#${CXX} -fsyntax-only ${DIR}windows.cpp +${CPPCHECK} --check-library --enable=information --enable=style --error-exitcode=1 --inline-suppr --library=windows ${DIR}windows.cpp + diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp new file mode 100644 index 000000000..a2ef1bc8f --- /dev/null +++ b/test/cfg/std.cpp @@ -0,0 +1,25 @@ + +// Test library configuration for std.cfg +// +// Usage: +// $ cppcheck --check-library --enable=information --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr test/cfg/std.cpp +// => +// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 +// + +#include +#include +#include + +void bufferAccessOutOf(void) { + char a[5]; + std::strcpy(a,"abcd"); + // cppcheck-suppress bufferAccessOutOfBounds + // cppcheck-suppress redundantCopy + std::strcpy(a, "abcde"); + // cppcheck-suppress redundantCopy + std::strncpy(a,"abcde",5); + // cppcheck-suppress bufferAccessOutOfBounds + // cppcheck-suppress redundantCopy + std::strncpy(a,"abcde",6); +}