Execution Paths: fixed TODO test cases

This commit is contained in:
Daniel Marjamäki 2010-09-17 19:31:45 +02:00
parent d9e7dd4d31
commit 1c3862bd35
2 changed files with 21 additions and 21 deletions

View File

@ -150,6 +150,15 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
for (; tok; tok = tok->next())
{
// might be a noreturn function..
if (Token::simpleMatch(tok->tokAt(-2), ") ; }") &&
Token::Match(tok->tokAt(-2)->link()->tokAt(-2), "[;{}] %var% (") &&
tok->tokAt(-2)->link()->previous()->varId() == 0)
{
ExecutionPath::bailOut(checks);
return;
}
if (tok->str() == "}" || tok->str() == "break")
return;
@ -307,15 +316,6 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
return;
}
// might be a noreturn function..
if (Token::Match(tok->previous(), "[;{}] %var% (") &&
Token::simpleMatch(tok->next()->link(), ") ; }") &&
tok->varId() == 0)
{
ExecutionPath::bailOut(checks);
return;
}
// don't parse into "struct type { .."
if (Token::Match(tok, "struct|union|class %type% {|:"))
{

View File

@ -1094,13 +1094,13 @@ private:
" const char * x = 0;\n"
" strdup(x);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
checkNullPointer("void foo()\n"
"{\n"
" char const * x = 0;\n"
" strdup(x);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
}
void nullpointer9() //#ticket 1778
@ -1228,7 +1228,7 @@ private:
" int a;\n"
" bar(4 * a);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
@ -1870,21 +1870,21 @@ private:
" char s[20];\n"
" strcpy(s2, s);\n"
"};\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char s[20];\n"
" strcat(s, \"abc\");\n"
"};\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
" char s[20];\n"
" strchr(s, ' ');\n"
"};\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void foo()\n"
"{\n"
@ -1905,7 +1905,7 @@ private:
" char *s = malloc(100);\n"
" strcat(s, \"abc\");\n"
"};\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2095,7 +2095,7 @@ private:
" strncpy(a, s, 20);\n"
" strncat(a, s, 20);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2103,7 +2103,7 @@ private:
" strncpy(a, \"hello\", 3);\n"
" strncat(a, \"world\", 20);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2173,7 +2173,7 @@ private:
" FILE *f;\n"
" fflush(f);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2202,14 +2202,14 @@ private:
" int x;\n"
" foo(x);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar("void foo(const char *s)\n"
"{\n"
" char *p;\n"
" memcpy(p, s, 100);\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("void foo(const char *s)\n"
"{\n"