value flow: improved error message output for conditional division by zero
This commit is contained in:
parent
a5b79bc968
commit
39b47cc1e7
|
@ -2304,6 +2304,24 @@ void CheckOther::checkZeroDivisionOrUselessCondition()
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: this utility function should probably be moved to some common file
|
||||
static std::string astStringify(const Token *top)
|
||||
{
|
||||
const Token *start = top;
|
||||
while (start->astOperand1() && start->astOperand2())
|
||||
start = start->astOperand1();
|
||||
const Token *end = top;
|
||||
while (end->astOperand1() && end->astOperand2())
|
||||
end = end->astOperand2();
|
||||
std::string str;
|
||||
for (const Token *tok = start; tok && tok != end; tok = tok->next()) {
|
||||
str += tok->str();
|
||||
if (Token::Match(tok, "%var%|%num% %var%|%num%"))
|
||||
str += " ";
|
||||
}
|
||||
return str + end->str();
|
||||
}
|
||||
|
||||
void CheckOther::zerodivcondError(const Token *tokcond, const Token *tokdiv)
|
||||
{
|
||||
std::list<const Token *> callstack;
|
||||
|
@ -2314,9 +2332,13 @@ void CheckOther::zerodivcondError(const Token *tokcond, const Token *tokdiv)
|
|||
callstack.push_back(tokdiv);
|
||||
}
|
||||
std::string condition;
|
||||
if (Token::Match(tokcond, "%num% <|<=")) {
|
||||
if (!tokcond) {
|
||||
// getErrorMessages
|
||||
} else if (Token::Match(tokcond, "%num% <|<=")) {
|
||||
condition = tokcond->strAt(2) + ((tokcond->strAt(1) == "<") ? ">" : ">=") + tokcond->str();
|
||||
} else if (tokcond) {
|
||||
} else if (tokcond->isComparisonOp()) {
|
||||
condition = astStringify(tokcond);
|
||||
} else {
|
||||
if (tokcond->str() == "!")
|
||||
condition = tokcond->next()->str() + "==0";
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue