Uninitialized variables: Fixed FP when taking address of uninitialized variable
This commit is contained in:
parent
7fe923bfc5
commit
80dec5a976
|
@ -1726,7 +1726,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
|||
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
|
||||
if (vartok->previous()->str() == "&") {
|
||||
const Token *tok2 = vartok->tokAt(-2);
|
||||
if (tok2 && (tok2->isConstOp() || Token::Match(tok2, "[;{}(]")))
|
||||
if (tok2 && (tok2->isConstOp() || Token::Match(tok2, "[;{}(=]")))
|
||||
return false; // address of
|
||||
if (tok2 && tok2->str() == ")")
|
||||
tok2 = tok2->link()->previous();
|
||||
|
|
|
@ -2142,6 +2142,12 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
" char *p = (char*)&x + 1;\n"
|
||||
"}", "test.cpp", false); // verify=false (the cast is removed but we don't care)
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int i;\n"
|
||||
" i=f(), i!=2;\n"
|
||||
|
|
Loading…
Reference in New Issue