From e48d785ea46f3f3823b3fe86de3106e48c629e96 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Thu, 16 May 2019 17:49:33 +0200 Subject: [PATCH] gnu.cfg: Added tests for mkostemp(), mkstemps() and mkostemps() functions. The test script 'test/cfg/runtests.sh' is now loading posix.cfg when checking gnu.cfg. Otherwise 'close()' was not available to Cppcheck, which lead to an error when 'make checkcfg' was executed. --- test/cfg/gnu.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ test/cfg/runtests.sh | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index 821f4ebc3..c5672eb52 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -15,6 +15,59 @@ #include #endif +void resourceLeak_mkostemps(char *template, int suffixlen, int flags) +{ + // cppcheck-suppress unreadVariable + int fp = mkostemps(template, suffixlen, flags); + // cppcheck-suppress resourceLeak +} + +void no_resourceLeak_mkostemps_01(char *template, int suffixlen, int flags) +{ + int fp = mkostemps(template, suffixlen, flags); + close(fp); +} + +int no_resourceLeak_mkostemps_02(char *template, int suffixlen, int flags) +{ + return mkostemps(template, suffixlen, flags); +} + +void resourceLeak_mkstemps(char *template, int suffixlen) +{ + // cppcheck-suppress unreadVariable + int fp = mkstemps(template, suffixlen); + // cppcheck-suppress resourceLeak +} + +void no_resourceLeak_mkstemps_01(char *template, int suffixlen) +{ + int fp = mkstemps(template, suffixlen); + close(fp); +} + +int no_resourceLeak_mkstemps_02(char *template, int suffixlen) +{ + return mkstemps(template, suffixlen); +} + +void resourceLeak_mkostemp(char *template, int flags) +{ + // cppcheck-suppress unreadVariable + int fp = mkostemp(template, flags); + // cppcheck-suppress resourceLeak +} + +void no_resourceLeak_mkostemp_01(char *template, int flags) +{ + int fp = mkostemp(template, flags); + close(fp); +} + +int no_resourceLeak_mkostemp_02(char *template, int flags) +{ + return mkostemp(template, flags); +} void valid_code(int argInt1) { diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 7e00a00cf..1b333daaa 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -37,7 +37,7 @@ ${CPPCHECK} ${CPPCHECK_OPT} --library=posix ${DIR}posix.c # gnu.c ${CC} ${CC_OPT} -D_GNU_SOURCE ${DIR}gnu.c -${CPPCHECK} ${CPPCHECK_OPT} --library=gnu ${DIR}gnu.c +${CPPCHECK} ${CPPCHECK_OPT} --library=posix,gnu ${DIR}gnu.c # qt.cpp set +e