| 2487 | } |
| 2488 | |
| 2489 | void CheckOtherImpl::zerodivError(const Token *tok, const ValueFlow::Value *value) |
| 2490 | { |
| 2491 | if (!tok && !value) { |
| 2492 | reportError(tok, Severity::error, "zerodiv", "Division by zero.", CWE369, Certainty::normal); |
| 2493 | reportError(tok, Severity::warning, "zerodivcond", ValueFlow::eitherTheConditionIsRedundant(nullptr) + " or there is division by zero.", CWE369, Certainty::normal); |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | ErrorPath errorPath = getErrorPath(tok, value, "Division by zero"); |
| 2498 | |
| 2499 | std::ostringstream errmsg; |
| 2500 | if (value->condition) { |
| 2501 | const int line = tok ? tok->linenr() : 0; |
| 2502 | errmsg << ValueFlow::eitherTheConditionIsRedundant(value->condition) |
| 2503 | << " or there is division by zero at line " << line << "."; |
| 2504 | } else |
| 2505 | errmsg << "Division by zero."; |
| 2506 | |
| 2507 | reportError(std::move(errorPath), |
| 2508 | value->errorSeverity() ? Severity::error : Severity::warning, |
| 2509 | value->condition ? "zerodivcond" : "zerodiv", |
| 2510 | errmsg.str(), CWE369, value->isInconclusive() ? Certainty::inconclusive : Certainty::normal); |
| 2511 | } |
| 2512 | |
| 2513 | //--------------------------------------------------------------------------- |
| 2514 | // Check for NaN (not-a-number) in an arithmetic expression, e.g. |
no test coverage detected