| 4359 | } |
| 4360 | |
| 4361 | void 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 | |
| 4391 | void CheckOtherImpl::knownPointerToBoolError(const Token* tok, const ValueFlow::Value* value) |
| 4392 | { |
no test coverage detected