Refactoring: Use AST in CheckUninitVar::isVariableUsage() to determine if & operator is address-of. This fixes FP in linux.
This commit is contained in:
parent
11fa185cae
commit
8dd569b9e1
|
@ -1748,29 +1748,8 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
||||||
}
|
}
|
||||||
|
|
||||||
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
|
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
|
||||||
if (vartok->previous()->str() == "&") {
|
if (vartok->previous()->str() == "&" && !vartok->previous()->astOperand2())
|
||||||
const Token *tok2 = vartok->tokAt(-2);
|
return false;
|
||||||
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() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
|
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
|
||||||
if (alloc && vartok->previous()->str() == "*") {
|
if (alloc && vartok->previous()->str() == "*") {
|
||||||
|
|
Loading…
Reference in New Issue