Fixed #3926 (false postive: (error) Uninitialized variable: exitpattern)

This commit is contained in:
Daniel Marjamäki 2012-07-03 18:52:23 +02:00
parent 25c1cc4c8e
commit f9da83f4b5
2 changed files with 27 additions and 0 deletions

View File

@ -1268,6 +1268,27 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
return false;
}
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
if (vartok->previous()->str() == "&") {
const Token *tok2 = vartok->tokAt(-2);
if (Token::simpleMatch(tok2,")"))
tok2 = tok2->link()->previous();
while (tok2 && tok2->str() == "(")
tok2 = tok2->previous();
while (tok2 && tok2->str() == "*")
tok2 = tok2->previous();
if (Token::Match(tok2, "[;{}] *")) {
// there is some such code before vartok: "[*]+ [(]* &"
// determine if there is a = after vartok
for (tok2 = vartok; tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "[;{}]"))
break;
if (tok2->str() == "=")
return false;
}
}
}
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
return true;
}

View File

@ -1928,6 +1928,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n" // #3926 - weird cast.
" int x;\n"
" *(((char *)&x) + 0) = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
// using uninit var in condition
checkUninitVar2("void f() {\n"
" int x;\n"