Uninitialized variables: Fixed FP when taking address of uninitialized variable

This commit is contained in:
Daniel Marjamäki 2013-12-13 20:10:22 +01:00
parent 7fe923bfc5
commit 80dec5a976
2 changed files with 7 additions and 1 deletions

View File

@ -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();

View File

@ -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"