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

Function if_findCompare

lib/checkstl.cpp:1497–1516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1495}
1496
1497static bool if_findCompare(const Token * const tokBack, bool stdStringLike)
1498{
1499 const Token *tok = tokBack->astParent();
1500 if (!tok)
1501 return true;
1502 if (tok->isComparisonOp()) {
1503 if (stdStringLike) {
1504 const Token * const tokOther = tokBack->astSibling();
1505 return !tokOther || !tokOther->hasKnownIntValue() || tokOther->getKnownIntValue() != 0;
1506 }
1507 return (!tok->astOperand1()->isNumber() && !tok->astOperand2()->isNumber());
1508 }
1509 if (tok->isArithmeticalOp()) // result is used in some calculation
1510 return true; // TODO: check if there is a comparison of the result somewhere
1511 if (tok->str() == ".")
1512 return true; // Dereferencing is OK, the programmer might know that the element exists - TODO: An inconclusive warning might be appropriate
1513 if (tok->isAssignmentOp())
1514 return if_findCompare(tok, stdStringLike); // Go one step upwards in the AST
1515 return false;
1516}
1517
1518void CheckStlImpl::if_find()
1519{

Callers 1

if_findMethod · 0.85

Calls 8

astParentMethod · 0.80
getKnownIntValueMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
isArithmeticalOpMethod · 0.80
isAssignmentOpMethod · 0.80
hasKnownIntValueMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected