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

Function isAddressOfLocalVariable

lib/checkautovariables.cpp:165–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static bool isAddressOfLocalVariable(const Token *expr)
166{
167 if (!expr)
168 return false;
169 if (Token::Match(expr, "+|-"))
170 return isAddressOfLocalVariable(expr->astOperand1()) || isAddressOfLocalVariable(expr->astOperand2());
171 if (expr->isCast())
172 return isAddressOfLocalVariable(expr->astOperand2() ? expr->astOperand2() : expr->astOperand1());
173 if (expr->isUnaryOp("&")) {
174 const Token *op = expr->astOperand1();
175 bool deref = false;
176 while (Token::Match(op, ".|[")) {
177 if (op->originalName() == "->")
178 return false;
179 if (op->str() == "[")
180 deref = true;
181 op = op->astOperand1();
182 }
183 return op && isAutoVar(op) && (!deref || !op->variable()->isPointer());
184 }
185 return false;
186}
187
188static bool variableIsUsedInScope(const Token* start, nonneg int varId, const Scope *scope)
189{

Callers 1

isAutoVariableRHSFunction · 0.85

Calls 7

isAutoVarFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
isCastMethod · 0.80
isUnaryOpMethod · 0.80
variableMethod · 0.80
strMethod · 0.45

Tested by

no test coverage detected