From ed36856451b0a77ea0d5c0a66f4f5ab3377238db Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Sat, 11 Jul 2020 00:02:28 +0200 Subject: [PATCH] Refactor: Use visitAstNodes in checkuninitvar --- lib/checkuninitvar.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index e46f94304..c1b9d6454 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -881,22 +881,17 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const usetok = tok; else if (tok->strAt(1) == "=") { bool varIsUsedInRhs = false; - std::stack tokens; - tokens.push(tok->next()->astOperand2()); - while (!tokens.empty()) { - const Token *t = tokens.top(); - tokens.pop(); + visitAstNodes(tok->next()->astOperand2(), [&](const Token * t) { if (!t) - continue; + return ChildrenToVisit::none; if (t->varId() == var.declarationId()) { varIsUsedInRhs = true; - break; + return ChildrenToVisit::done; } if (Token::simpleMatch(t->previous(),"sizeof (")) - continue; - tokens.push(t->astOperand1()); - tokens.push(t->astOperand2()); - } + return ChildrenToVisit::none; + return ChildrenToVisit::op1_and_op2; + }); if (!varIsUsedInRhs) return true; } else {