Fixed #2030 (False positive: Uninitialized variable when function does not return)

This commit is contained in:
Daniel Marjamäki 2010-09-10 19:02:40 +02:00
parent 940679e242
commit 0418731473
2 changed files with 15 additions and 15 deletions

View File

@ -305,9 +305,9 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
}
// might be a noreturn function..
if (tok->varId() == 0 &&
(Token::Match(tok->previous(), "[;{}] %var% ( ) ; }") ||
Token::Match(tok->previous(), "[;{}] %var% ( %num% ) ; }")))
if (Token::Match(tok->previous(), "[;{}] %var% (") &&
Token::simpleMatch(tok->next()->link(), ") ; }") &&
tok->varId() == 0)
{
ExecutionPath::bailOut(checks);
return;

View File

@ -1229,13 +1229,13 @@ private:
" const char * x = 0;\n"
" strdup(x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
TODO_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");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
}
void nullpointer9() //#ticket 1778
@ -1363,7 +1363,7 @@ private:
" int a;\n"
" bar(4 * a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
@ -1998,21 +1998,21 @@ private:
" char s[20];\n"
" strcpy(s2, s);\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
TODO_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");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
TODO_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");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void foo()\n"
"{\n"
@ -2033,7 +2033,7 @@ private:
" char *s = malloc(100);\n"
" strcat(s, \"abc\");\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2223,7 +2223,7 @@ private:
" strncpy(a, s, 20);\n"
" strncat(a, s, 20);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
TODO_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"
@ -2231,7 +2231,7 @@ private:
" strncpy(a, \"hello\", 3);\n"
" strncat(a, \"world\", 20);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it)\n", errout.str());
TODO_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"
@ -2301,7 +2301,7 @@ private:
" FILE *f;\n"
" fflush(f);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
checkUninitVar("void f()\n"
"{\n"
@ -2330,14 +2330,14 @@ private:
" int x;\n"
" foo(x);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: x\n", errout.str());
TODO_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");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("void foo(const char *s)\n"
"{\n"