Fixed #4439 (False positive: Uninitialized variable (casting address))
This commit is contained in:
parent
34b3fe6af0
commit
1f04e2c228
|
@ -1534,6 +1534,8 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp
|
||||||
return false; // address of
|
return false; // address of
|
||||||
if (tok2 && tok2->str() == ")")
|
if (tok2 && tok2->str() == ")")
|
||||||
tok2 = tok2->link()->previous();
|
tok2 = tok2->link()->previous();
|
||||||
|
if (Token::Match(tok2,") ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0)
|
||||||
|
return false; // cast
|
||||||
while (tok2 && tok2->str() == "(")
|
while (tok2 && tok2->str() == "(")
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
while (tok2 && tok2->str() == "*")
|
while (tok2 && tok2->str() == "*")
|
||||||
|
|
|
@ -2344,6 +2344,12 @@ private:
|
||||||
" if (&a == &b);\n"
|
" if (&a == &b);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar2("void f() {\n" // #4439 - cast address of uninitialized variable
|
||||||
|
" int a;\n"
|
||||||
|
" x((A)(B)&a);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// #3869 - reference variable
|
// #3869 - reference variable
|
||||||
|
|
Loading…
Reference in New Issue