| 265 | } |
| 266 | |
| 267 | void CheckNullPointerImpl::nullPointerByDeRefAndCheck() |
| 268 | { |
| 269 | const bool printInconclusive = (mSettings.certainty.isEnabled(Certainty::inconclusive)); |
| 270 | |
| 271 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 272 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 273 | auto pred = [printInconclusive](const Token* tok) -> bool { |
| 274 | if (!tok) |
| 275 | return false; |
| 276 | |
| 277 | if (Token::Match(tok, "%num%|%char%|%str%")) |
| 278 | return false; |
| 279 | |
| 280 | if (!isNullablePointer(tok) || |
| 281 | (tok->str() == "." && isNullablePointer(tok->astOperand2()) && tok->astOperand2()->getValue(0))) // avoid duplicate warning |
| 282 | return false; |
| 283 | |
| 284 | // Can pointer be NULL? |
| 285 | const ValueFlow::Value *value = tok->getValue(0); |
| 286 | if (!value) |
| 287 | return false; |
| 288 | |
| 289 | if (!printInconclusive && value->isInconclusive()) |
| 290 | return false; |
| 291 | |
| 292 | return true; |
| 293 | }; |
| 294 | const Token* const start = (scope->function && scope->function->isConstructor()) ? scope->function->token : scope->bodyStart; // Check initialization list |
| 295 | std::vector<const Token *> tokens = findTokensSkipDeadAndUnevaluatedCode(mSettings.library, start, scope->bodyEnd, pred); |
| 296 | for (const Token *tok : tokens) { |
| 297 | const ValueFlow::Value *value = tok->getValue(0); |
| 298 | |
| 299 | // Pointer dereference. |
| 300 | bool unknown = false; |
| 301 | if (!CheckNullPointerImpl::isPointerDeRef(tok, unknown, mSettings)) { |
| 302 | if (unknown) |
| 303 | nullPointerError(tok, tok->expressionString(), value, true); |
| 304 | continue; |
| 305 | } |
| 306 | |
| 307 | nullPointerError(tok, tok->expressionString(), value, value->isInconclusive()); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void CheckNullPointerImpl::nullPointer() |
| 313 | { |
nothing calls this directly
no test coverage detected