MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / redundantConditionWarning

Method redundantConditionWarning

lib/checknullpointer.cpp:557–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557void CheckNullPointerImpl::redundantConditionWarning(const Token* tok, const ValueFlow::Value *value, const Token *condition, bool inconclusive)
558{
559 // cppcheck-suppress shadowFunction - TODO: fix this
560 std::string arithmetic = arithmeticTypeString(tok);
561 std::string errmsg;
562 if (tok && tok->str()[0] == '-') {
563 errmsg = ValueFlow::eitherTheConditionIsRedundant(condition) + " or there is overflow in pointer " + arithmetic + ".";
564 } else {
565 errmsg = ValueFlow::eitherTheConditionIsRedundant(condition) + " or there is pointer arithmetic with NULL pointer.";
566 }
567 ErrorPath errorPath = getErrorPath(tok, value, "Null pointer " + arithmetic);
568 reportError(std::move(errorPath),
569 Severity::warning,
570 "nullPointerArithmeticRedundantCheck",
571 errmsg,
572 CWE_INCORRECT_CALCULATION,
573 inconclusive ? Certainty::inconclusive : Certainty::normal);
574}
575
576// NOLINTNEXTLINE(readability-non-const-parameter) - used as callback so we need to preserve the signature
577static bool isUnsafeUsage(const Settings &settings, const Token *vartok, CTU::FileInfo::Value *value)

Callers 1

getErrorMessagesMethod · 0.80

Calls 3

arithmeticTypeStringFunction · 0.85
reportErrorFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected