Fixed #2753 (False negative: dereference uninitialized pointer 'buf[0] = 0;')

This commit is contained in:
Daniel Marjamäki 2011-04-26 20:26:09 +02:00
parent 6d858b63a1
commit e22f69daf4
2 changed files with 12 additions and 0 deletions

View File

@ -507,6 +507,11 @@ private:
const Token *tok2 = tok.next();
if (tok2->str() == "[" && Token::simpleMatch(tok2->link(), "] ="))
{
if (use_dead_pointer(checks, &tok))
{
return &tok;
}
parserhs(tok2, checks);
tok2 = tok2->link()->next();
}

View File

@ -127,6 +127,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *p;\n"
" p[0] = 135;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *x;\n"