Refactor: Use visitAstNodes in checkuninitvar
This commit is contained in:
parent
9ced26a7a1
commit
ed36856451
|
@ -881,22 +881,17 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
|
||||||
usetok = tok;
|
usetok = tok;
|
||||||
else if (tok->strAt(1) == "=") {
|
else if (tok->strAt(1) == "=") {
|
||||||
bool varIsUsedInRhs = false;
|
bool varIsUsedInRhs = false;
|
||||||
std::stack<const Token *> tokens;
|
visitAstNodes(tok->next()->astOperand2(), [&](const Token * t) {
|
||||||
tokens.push(tok->next()->astOperand2());
|
|
||||||
while (!tokens.empty()) {
|
|
||||||
const Token *t = tokens.top();
|
|
||||||
tokens.pop();
|
|
||||||
if (!t)
|
if (!t)
|
||||||
continue;
|
return ChildrenToVisit::none;
|
||||||
if (t->varId() == var.declarationId()) {
|
if (t->varId() == var.declarationId()) {
|
||||||
varIsUsedInRhs = true;
|
varIsUsedInRhs = true;
|
||||||
break;
|
return ChildrenToVisit::done;
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(t->previous(),"sizeof ("))
|
if (Token::simpleMatch(t->previous(),"sizeof ("))
|
||||||
continue;
|
return ChildrenToVisit::none;
|
||||||
tokens.push(t->astOperand1());
|
return ChildrenToVisit::op1_and_op2;
|
||||||
tokens.push(t->astOperand2());
|
});
|
||||||
}
|
|
||||||
if (!varIsUsedInRhs)
|
if (!varIsUsedInRhs)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue