From e5c098c7deb9553fa4ed4258276763585513528c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 17 Feb 2015 18:08:19 +0100 Subject: [PATCH] TestUninitVar: move out posix.cfg testing --- cfg/posix.cfg | 1 + test/cfg/posix.c | 11 ++++++++ test/testuninitvar.cpp | 59 ------------------------------------------ 3 files changed, 12 insertions(+), 59 deletions(-) diff --git a/cfg/posix.cfg b/cfg/posix.cfg index 53783c08e..7ef1234fc 100644 --- a/cfg/posix.cfg +++ b/cfg/posix.cfg @@ -441,6 +441,7 @@ + false diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 9aaf42881..b1d4f372f 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -114,3 +114,14 @@ void invalidFunctionArg() { // cppcheck-suppress invalidFunctionArg usleep(1000000); } + +void uninitvar(int fd) { + int x; + char buf[2]; + // cppcheck-suppress uninitvar + write(x,"ab",2); + // cppcheck-suppress uninitvar + write(fd,buf,2); + // cppcheck-suppress uninitvar + write(fd,"ab",x); +} diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index e6a2279ce..f28f5fc5b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3850,65 +3850,6 @@ private: ASSERT_EQUALS("[test.cpp:6]: (debug) assertion failed '} while ('\n", errout.str()); } - void uninitvar_posix_write() { // #6325 - // Load posix library file - LOAD_LIB_2(settings.library, "posix.cfg"); - - // check the first parameter of write - checkUninitVar("void uninitvar(char *buf)\n" - "{\n" - " int fd;\n" - " write(fd, buf, sizeof(buf));\n" - "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: fd\n", errout.str()); - - checkUninitVarB("void no_uninitvar(int fd, char *buf)\n" - "{\n" - " write(fd, buf, 8);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - - // check the second parameter of the posix function write - checkUninitVar("void uninitvar() {\n" - " char *buf;\n" - " write(STDOUT_FILENO, buf, sizeof(buf));\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str()); - - checkUninitVar("void uninitvar() {\n" - " char buf[2];\n" - " write(STDOUT_FILENO, buf, 2);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: buf\n", errout.str()); - - // avoid false positives - checkUninitVarB("void no_uninitvar(char *buf) {\n" - " write(STDOUT_FILENO, buf, 8);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - checkUninitVarB("void no_uninitvar() {\n" - " char buf[1] = {'c'};\n" - " write(STDOUT_FILENO, &buf, 1);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - - // check the third parameter of the posix function write - checkUninitVar2("void uninitvar(char *buf) {\n" - " int nbytes;\n" - " write(STDOUT_FILENO, buf, nbytes);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: nbytes\n", errout.str()); - - checkUninitVarB("void no_uninitvar(char *buf, int nbytes)\n" - "{\n" - " write(STDOUT_FILENO, buf, nbytes);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - void checkDeadPointer(const char code[]) { // Clear the error buffer.. errout.str("");