| 525 | } |
| 526 | |
| 527 | void CheckNullPointerImpl::pointerArithmeticError(const Token* tok, const ValueFlow::Value *value, bool inconclusive) |
| 528 | { |
| 529 | // cppcheck-suppress shadowFunction - TODO: fix this |
| 530 | std::string arithmetic = arithmeticTypeString(tok); |
| 531 | std::string errmsg; |
| 532 | if (tok && tok->str()[0] == '-') { |
| 533 | errmsg = "Overflow in pointer arithmetic, NULL pointer is subtracted."; |
| 534 | } else { |
| 535 | errmsg = "Pointer " + arithmetic + " with NULL pointer."; |
| 536 | } |
| 537 | |
| 538 | std::string id = "nullPointerArithmetic"; |
| 539 | if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { |
| 540 | errmsg = "If memory allocation fails: " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1)); |
| 541 | id += "OutOfMemory"; |
| 542 | } |
| 543 | else if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) { |
| 544 | errmsg = "If resource allocation fails: " + (static_cast<char>(std::tolower(errmsg[0])) + errmsg.substr(1)); |
| 545 | id += "OutOfResources"; |
| 546 | } |
| 547 | |
| 548 | ErrorPath errorPath = getErrorPath(tok, value, "Null pointer " + arithmetic); |
| 549 | reportError(std::move(errorPath), |
| 550 | Severity::error, |
| 551 | id.c_str(), |
| 552 | errmsg, |
| 553 | CWE_INCORRECT_CALCULATION, |
| 554 | inconclusive ? Certainty::inconclusive : Certainty::normal); |
| 555 | } |
| 556 | |
| 557 | void CheckNullPointerImpl::redundantConditionWarning(const Token* tok, const ValueFlow::Value *value, const Token *condition, bool inconclusive) |
| 558 | { |
no test coverage detected