Fixed #4737 (False positive: Uninitialized variable 'do_something(&((char*)&var)[0],1);')

This commit is contained in:
Daniel Marjamäki 2013-05-01 13:52:28 +02:00
parent 42068a3d60
commit 44cb070e13
2 changed files with 7 additions and 1 deletions

View File

@ -1549,7 +1549,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
return false; // address of
if (tok2 && tok2->str() == ")")
tok2 = tok2->link()->previous();
if (Token::Match(tok2,") ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0)
if (Token::Match(tok2,"[()] ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0)
return false; // cast
while (tok2 && tok2->str() == "(")
tok2 = tok2->previous();

View File

@ -2023,6 +2023,12 @@ private:
"}", "test.c", false);
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n" // #4737 - weird cast.
" int x;\n"
" do_something(&((char*)&x)[0], 1);\n"
"}");
ASSERT_EQUALS("", errout.str());
// using uninit var in condition
checkUninitVar2("void f(void) {\n"
" int x;\n"