| 4402 | } |
| 4403 | |
| 4404 | void CheckOtherImpl::checkComparePointers() |
| 4405 | { |
| 4406 | logChecker("CheckOther::checkComparePointers"); |
| 4407 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 4408 | for (const Scope *functionScope : symbolDatabase->functionScopes) { |
| 4409 | for (const Token *tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) { |
| 4410 | if (!Token::Match(tok, "<|>|<=|>=|-")) |
| 4411 | continue; |
| 4412 | const Token *tok1 = tok->astOperand1(); |
| 4413 | if (!astIsPointer(tok1)) |
| 4414 | continue; |
| 4415 | const Token *tok2 = tok->astOperand2(); |
| 4416 | if (!astIsPointer(tok2)) |
| 4417 | continue; |
| 4418 | ValueFlow::Value v1 = ValueFlow::getLifetimeObjValue(tok1); |
| 4419 | if (!v1.isLocalLifetimeValue()) |
| 4420 | continue; |
| 4421 | ValueFlow::Value v2 = ValueFlow::getLifetimeObjValue(tok2); |
| 4422 | if (!v2.isLocalLifetimeValue()) |
| 4423 | continue; |
| 4424 | const Variable *var1 = v1.tokvalue->variable(); |
| 4425 | const Variable *var2 = v2.tokvalue->variable(); |
| 4426 | if (!var1 || !var2) |
| 4427 | continue; |
| 4428 | if (v1.tokvalue->varId() == v2.tokvalue->varId()) |
| 4429 | continue; |
| 4430 | if (var1->isReference() || var2->isReference()) |
| 4431 | continue; |
| 4432 | if (var1->isRValueReference() || var2->isRValueReference()) |
| 4433 | continue; |
| 4434 | if (const Token* parent2 = getParentLifetime(v2.tokvalue, mSettings.library)) |
| 4435 | if (var1 == parent2->variable()) |
| 4436 | continue; |
| 4437 | if (const Token* parent1 = getParentLifetime(v1.tokvalue, mSettings.library)) |
| 4438 | if (var2 == parent1->variable()) |
| 4439 | continue; |
| 4440 | comparePointersError(tok, &v1, &v2); |
| 4441 | } |
| 4442 | } |
| 4443 | } |
| 4444 | |
| 4445 | void CheckOtherImpl::comparePointersError(const Token *tok, const ValueFlow::Value *v1, const ValueFlow::Value *v2) |
| 4446 | { |
no test coverage detected