From 9bbad1b62265815cb1bccfac551db0f97f52739e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 30 Jan 2015 06:43:40 +0100 Subject: [PATCH] TestNullPointer: Moved posix.cfg tests --- test/cfg/runtests.sh | 4 ++++ test/testnullpointer.cpp | 37 ------------------------------------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index ee6f9eea5..2b64195ff 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -9,6 +9,10 @@ else # assume we are in repo root DIR=./test/cfg/ fi +# posix.c +gcc -fsyntax-only ${DIR}posix.c +${CPPCHECK} --check-library --library=posix --enable=information --error-exitcode=1 --inline-suppr ${DIR}posix.c + # std.c gcc -fsyntax-only ${DIR}std.c ${CPPCHECK} --check-library --enable=information --error-exitcode=1 --inline-suppr ${DIR}std.c diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index d60d9e442..6d923b160 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -95,11 +95,6 @@ private: TEST_CASE(nullpointer_internal_error); // #5080 TEST_CASE(nullpointerFputc); // #5645 FP: Null pointer dereference in fputc argument TEST_CASE(nullpointerPutchar); - - // Load posix library file - LOAD_LIB_2(settings.library, "posix.cfg"); - // Test that posix.cfg is configured correctly - TEST_CASE(posixcfg); } void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) { @@ -2470,38 +2465,6 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str()); } - - void posixcfg() { - const char errp[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"; - - check("void f(FILE *p){ isatty (*p);if(!p){}}"); - ASSERT_EQUALS(errp,errout.str()); - - check("void f(){ isatty (0);}"); - ASSERT_EQUALS("",errout.str()); - - check("void f(char *p){ mkdir (p, 0);}"); - ASSERT_EQUALS("",errout.str()); - - check("void f(char *p){ int i = 0; mkdir (p, i);}"); - ASSERT_EQUALS("",errout.str()); - - check("void f(){ getcwd (0, 0);}"); - ASSERT_EQUALS("",errout.str()); - - check("void f(char *p){ mkdir (p, *0);}"); - ASSERT_EQUALS("[test.cpp:1]: (error) Null pointer dereference\n",errout.str()); - - check("void foo()\n" - "{\n" - " char const * x = 0;\n" - " strdup(x);\n" - "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str()); - - check("DIR* f(){ DIR *dirp = 0; return readdir (dirp);}"); - ASSERT_EQUALS("[test.cpp:1]: (error) Possible null pointer dereference: dirp\n",errout.str()); - } }; REGISTER_TEST(TestNullPointer)