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

Function valueFlowSmartPointer

lib/valueflow.cpp:6288–6361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6286}
6287
6288static void valueFlowSmartPointer(TokenList &tokenlist, ErrorLogger & errorLogger, const Settings &settings)
6289{
6290 for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
6291 if (!tok->scope())
6292 continue;
6293 if (!tok->scope()->isExecutable())
6294 continue;
6295 if (!astIsSmartPointer(tok))
6296 continue;
6297 if (tok->variable() && Token::Match(tok, "%var% (|{|;")) {
6298 const Variable* var = tok->variable();
6299 if (!var->isSmartPointer())
6300 continue;
6301 if (var->nameToken() == tok) {
6302 if (Token::Match(tok, "%var% (|{") && tok->next()->astOperand2() &&
6303 tok->next()->astOperand2()->str() != ",") {
6304 Token* inTok = tok->next()->astOperand2();
6305 const std::list<ValueFlow::Value>& values = inTok->values();
6306 const bool constValue = inTok->isNumber();
6307 valueFlowForwardAssign(inTok, var, values, constValue, true, tokenlist, errorLogger, settings);
6308
6309 } else if (Token::Match(tok, "%var% ;")) {
6310 ValueFlow::Value v(0);
6311 v.setKnown();
6312 valueFlowForwardAssign(tok, var, {std::move(v)}, false, true, tokenlist, errorLogger, settings);
6313 }
6314 }
6315 } else if (astIsLHS(tok) && Token::Match(tok->astParent(), ". %name% (") &&
6316 tok->astParent()->originalName() != "->") {
6317 std::vector<const Variable*> vars = getVariables(tok);
6318 Token* ftok = tok->astParent()->tokAt(2);
6319 if (Token::simpleMatch(tok->astParent(), ". reset (")) {
6320 if (Token::simpleMatch(ftok, "( )")) {
6321 ValueFlow::Value v(0);
6322 v.setKnown();
6323 valueFlowForwardAssign(ftok, tok, std::move(vars), {std::move(v)}, false, tokenlist, errorLogger, settings);
6324 } else {
6325 tok->removeValues(std::mem_fn(&ValueFlow::Value::isIntValue));
6326 Token* inTok = ftok->astOperand2();
6327 if (!inTok)
6328 continue;
6329 const std::list<ValueFlow::Value>& values = inTok->values();
6330 valueFlowForwardAssign(inTok, tok, std::move(vars), values, false, tokenlist, errorLogger, settings);
6331 }
6332 } else if (Token::simpleMatch(tok->astParent(), ". release ( )")) {
6333 const Token* parent = ftok->astParent();
6334 bool hasParentReset = false;
6335 while (parent) {
6336 if (Token::Match(parent->tokAt(-2), ". release|reset (") &&
6337 parent->tokAt(-2)->astOperand1()->exprId() == tok->exprId()) {
6338 hasParentReset = true;
6339 break;
6340 }
6341 parent = parent->astParent();
6342 }
6343 if (hasParentReset)
6344 continue;
6345 ValueFlow::Value v(0);

Callers 1

setValuesMethod · 0.85

Calls 15

astIsSmartPointerFunction · 0.85
valueFlowForwardAssignFunction · 0.85
astIsLHSFunction · 0.85
getVariablesFunction · 0.85
makeSymbolicFunction · 0.85
setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
scopeMethod · 0.80
variableMethod · 0.80
isSmartPointerMethod · 0.80
astOperand2Method · 0.80

Tested by

no test coverage detected