Refactoring: Use AST in CheckUninitVar::isVariableUsage() to determine if & operator is address-of. This fixes FP in linux.

This commit is contained in:
Daniel Marjamäki 2015-01-04 09:23:24 +01:00
parent 11fa185cae
commit 8dd569b9e1
1 changed files with 2 additions and 23 deletions

View File

@ -1748,29 +1748,8 @@ 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, "[;{}(=]")))
return false; // address of
if (tok2 && tok2->str() == ")")
tok2 = tok2->link()->previous();
if (Token::Match(tok2,"[()] ( %type% *| ) &") && tok2->tokAt(2)->varId() == 0)
return false; // cast
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() == "&" && !vartok->previous()->astOperand2())
return false;
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
if (alloc && vartok->previous()->str() == "*") {