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

Method checkKnownPointerToBool

lib/checkother.cpp:4361–4389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4359}
4360
4361void CheckOtherImpl::checkKnownPointerToBool()
4362{
4363 if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("knownPointerToBool"))
4364 return;
4365 logChecker("CheckOther::checkKnownPointerToBool"); // style
4366 const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
4367 for (const Scope* functionScope : symbolDatabase->functionScopes) {
4368 for (const Token* tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) {
4369 if (!tok->hasKnownIntValue())
4370 continue;
4371 if (!astIsPointer(tok))
4372 continue;
4373 if (Token::Match(tok->astParent(), "?|!|&&|%oror%|%comp%"))
4374 continue;
4375 if (tok->astParent() && Token::Match(tok->astParent()->previous(), "if|while|switch|sizeof ("))
4376 continue;
4377 if (tok->isExpandedMacro())
4378 continue;
4379 if (findParent(tok, [](const Token* parent) {
4380 return parent->isExpandedMacro();
4381 }))
4382 continue;
4383 if (!isUsedAsBool(tok, mSettings))
4384 continue;
4385 const ValueFlow::Value& value = tok->values().front();
4386 knownPointerToBoolError(tok, &value);
4387 }
4388 }
4389}
4390
4391void CheckOtherImpl::knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value)
4392{

Callers 1

runChecksMethod · 0.80

Calls 9

astIsPointerFunction · 0.85
findParentFunction · 0.85
isUsedAsBoolFunction · 0.85
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
astParentMethod · 0.80
frontMethod · 0.80
isEnabledMethod · 0.45
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected