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

Function isAutoVarArray

lib/checkautovariables.cpp:102–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102static bool isAutoVarArray(const Token *tok)
103{
104 if (!tok)
105 return false;
106
107 // &x[..]
108 if (tok->isUnaryOp("&") && Token::simpleMatch(tok->astOperand1(), "["))
109 return isAutoVarArray(tok->astOperand1()->astOperand1());
110
111 // x+y
112 if (tok->str() == "+")
113 return isAutoVarArray(tok->astOperand1()) || isAutoVarArray(tok->astOperand2());
114
115 // x-intexpr
116 if (tok->str() == "-")
117 return isAutoVarArray(tok->astOperand1()) &&
118 tok->astOperand2() &&
119 tok->astOperand2()->valueType() &&
120 tok->astOperand2()->valueType()->isIntegral();
121
122 const Variable *var = tok->variable();
123 if (!var)
124 return false;
125
126 // Variable
127 if (var->isLocal() && !var->isStatic() && var->isArray() && !var->isPointer())
128 return true;
129
130 // ValueFlow
131 if (var->isPointer() && !var->isArgument()) {
132 for (auto it = tok->values().cbegin(); it != tok->values().cend(); ++it) {
133 const ValueFlow::Value &val = *it;
134 if (val.isTokValue() && isAutoVarArray(val.tokvalue))
135 return true;
136 }
137 }
138
139 return false;
140}
141
142static bool isLocalContainerBuffer(const Token* tok, const Settings& settings)
143{

Callers 1

isAutoVariableRHSFunction · 0.85

Calls 8

isUnaryOpMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
isIntegralMethod · 0.80
variableMethod · 0.80
isArrayMethod · 0.80
simpleMatchFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected