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

Function ifvar

lib/checkmemoryleak.cpp:397–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395}
396
397static bool ifvar(const Token *tok, nonneg int varid, const std::string &comp, const std::string &rhs)
398{
399 if (!Token::simpleMatch(tok, "if ("))
400 return false;
401 const Token *condition = tok->next()->astOperand2();
402 if (condition && condition->str() == "(" && Token::Match(condition->astOperand1(), "UNLIKELY|LIKELY"))
403 condition = condition->astOperand2();
404 if (!condition || condition->str() == "&&")
405 return false;
406
407 const Token *vartok = astIsVariableComparison(condition, comp, rhs);
408 return (vartok && vartok->varId() == varid);
409}
410
411//---------------------------------------------------------------------------
412// Check for memory leaks due to improper realloc() usage.

Callers 1

checkStructVariableMethod · 0.85

Calls 6

astIsVariableComparisonFunction · 0.85
astOperand2Method · 0.80
nextMethod · 0.80
astOperand1Method · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected