Fixed #2207 (False positive: uninitialized variable (return if uninitialized))
This commit is contained in:
parent
d250cb5aa2
commit
29bb553782
|
@ -425,6 +425,20 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
|
|||
if (countif.find((*it)->varId) != countif.end())
|
||||
(*it)->numberOfIf++;
|
||||
}
|
||||
|
||||
// Delete checks that have numberOfIf >= 2
|
||||
for (it = checks.begin(); it != checks.end();)
|
||||
{
|
||||
if ((*it)->varId > 0 && (*it)->numberOfIf >= 2)
|
||||
{
|
||||
delete *it;
|
||||
checks.erase(it++);
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -405,7 +405,8 @@ private:
|
|||
" p = new FooCar;\n"
|
||||
" p->abcd();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("static void foo()\n"
|
||||
"{\n"
|
||||
|
|
|
@ -546,6 +546,27 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #2207 - False negative
|
||||
checkUninitVar("void foo(int x) {\n"
|
||||
" int a;\n"
|
||||
" if (x)\n"
|
||||
" a = 1;\n"
|
||||
" b = c - a;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:5] (error) uninitialized variable a", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #2207 - False positive
|
||||
checkUninitVar("void foo(int x) {\n"
|
||||
" int a;\n"
|
||||
" if (x)\n"
|
||||
" a = 1;\n"
|
||||
" if (!x)\n"
|
||||
" return;\n"
|
||||
" b = (c - a);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("int foo()\n"
|
||||
"{\n"
|
||||
" int ret;\n"
|
||||
|
|
Loading…
Reference in New Issue