Uninitialized variables: fixed false negative when using uninitialized variable inside malloc call

This commit is contained in:
Daniel Marjamäki 2010-05-30 10:30:51 +02:00
parent 1ec49430e3
commit 37ae4692bb
2 changed files with 8 additions and 1 deletions

View File

@ -2960,7 +2960,7 @@ private:
{
alloc_pointer(checks, tok.varId());
if (tok.tokAt(3)->str() == "(")
return tok.tokAt(3)->link();
return tok.tokAt(3);
}
else if (Token::simpleMatch(tok.previous(), ">>") || Token::simpleMatch(tok.next(), "="))

View File

@ -1176,6 +1176,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
checkUninitVar("void f(Foo *p)\n"
"{\n"
" int a;\n"
" p->a = malloc(4 * a);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("static void foo()\n"
"{\n"
" int *p;\n"