Fixed #1712 (False negative: dereferencing uninitialized pointer)

This commit is contained in:
Daniel Marjamäki 2010-05-27 19:00:52 +02:00
parent dc34a1b3ff
commit d3c20cac81
2 changed files with 16 additions and 3 deletions

View File

@ -245,16 +245,20 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it)
{
c.push_back((*it)->copy());
if ((*it)->varId != 0)
{
c.push_back((*it)->copy());
countif2.insert((*it)->varId);
}
}
}
checkExecutionPaths_(tok->next(), c);
while (!c.empty())
{
if (c.back()->varId == 0)
{
c.pop_back();
continue;
}
bool duplicate = false;
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it)

View File

@ -1411,6 +1411,15 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
checkNullPointer("void f(int a)\n"
"{\n"
" if (a) {\n"
" char *p;\n"
" *p = 0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: p\n", errout.str());
// +=
checkUninitVar("void f()\n"
"{\n"