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"))
return true;
if (Token::Match(prev, "%varid% =", var->declarationId()))
return true;
// bailout; if variable is used previously that is checked first
if (!scopeStart && prev->varId() == var->declarationId())
if (Token::Match(prev, "%varid% =", var->declarationId())) {
bool usedInRhs = false;
visitAstNodes(prev->next()->astOperand2(), [&usedInRhs, var](const Token *tok) {
if (tok->varId() == var->declarationId()) {
usedInRhs = true;
return ChildrenToVisit::done;
}
return ChildrenToVisit::op1_and_op2;
});
if (!usedInRhs)
return true;
}
}
return false;
}