Bug hunting; Fix TestBughuntingChecks

This commit is contained in:
Daniel Marjamäki 2020-07-17 11:02:46 +02:00
parent 592637af61
commit f2bd603bd3
1 changed files with 12 additions and 6 deletions

View File

@ -180,13 +180,19 @@ static bool isVariableAssigned(const Variable *var, const Token *tok, const Toke
} }
if (scopeStart && Token::Match(prev, "return|throw|continue|break")) if (scopeStart && Token::Match(prev, "return|throw|continue|break"))
return true; return true;
if (Token::Match(prev, "%varid% =", var->declarationId())) if (Token::Match(prev, "%varid% =", var->declarationId())) {
return true; bool usedInRhs = false;
visitAstNodes(prev->next()->astOperand2(), [&usedInRhs, var](const Token *tok) {
// bailout; if variable is used previously that is checked first if (tok->varId() == var->declarationId()) {
if (!scopeStart && prev->varId() == var->declarationId()) usedInRhs = true;
return ChildrenToVisit::done;
}
return ChildrenToVisit::op1_and_op2;
});
if (!usedInRhs)
return true; return true;
} }
}
return false; return false;
} }