Uninitialized variables. Fixed false positive when there are multiple related conditions. ticket: #2399

This commit is contained in:
Daniel Marjamäki 2011-01-05 19:54:56 +01:00
parent a0d62e041f
commit 68de938d23
3 changed files with 15 additions and 2 deletions

View File

@ -122,7 +122,7 @@ static void parseIfSwitchBody(const Token * const tok,
std::list<ExecutionPath *>::const_iterator it; std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it) for (it = checks.begin(); it != checks.end(); ++it)
{ {
if (*(*it) == *c.back()) if (*(*it) == *c.back() && (*it)->numberOfIf == c.back()->numberOfIf)
{ {
duplicate = true; duplicate = true;
countif2.erase((*it)->varId); countif2.erase((*it)->varId);

View File

@ -597,7 +597,8 @@ private:
" }\n" " }\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
ASSERT_EQUALS("", errout.str());
} }
void eraseGoto() void eraseGoto()

View File

@ -637,6 +637,18 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("int test(int cond1, int cond2) {\n"
" int foo;\n"
" if (cond1 || cond2) {\n"
" if (cond2)\n"
" foo = 0;\n"
" }\n"
" if (cond2) {\n"
" int t = foo*foo;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// ? : // ? :
checkUninitVar("static void foo(int v)\n" checkUninitVar("static void foo(int v)\n"
"{\n" "{\n"