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

Method byVal

lib/valueflow.cpp:2169–2245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2167
2168 template<class Predicate>
2169 bool byVal(Token* tok,
2170 const TokenList& tokenlist,
2171 ErrorLogger& errorLogger,
2172 const Settings& settings,
2173 const Predicate& pred,
2174 SourceLocation loc = SourceLocation::current())
2175 {
2176 if (!argtok)
2177 return false;
2178 bool update = false;
2179 if (argtok->values().empty()) {
2180 ErrorPath er;
2181 er.emplace_back(argtok, message);
2182 for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(argtok, settings)) {
2183 if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive)
2184 continue;
2185
2186 const Variable* var = lt.token->variable();
2187 if (!var || !var->isArgument())
2188 continue;
2189
2190 ValueFlow::Value value;
2191 value.valueType = ValueFlow::Value::ValueType::LIFETIME;
2192 value.tokvalue = lt.token;
2193 value.capturetok = argtok;
2194 value.errorPath = er;
2195 value.lifetimeKind = type;
2196 value.setInconclusive(inconclusive || lt.inconclusive);
2197 value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument;
2198
2199 // Don't add the value a second time
2200 if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
2201 continue;
2202 if (settings.debugnormal)
2203 setSourceLocation(value, loc, tok);
2204 setTokenValue(tok, std::move(value), settings);
2205 update = true;
2206 }
2207 }
2208 for (const ValueFlow::Value &v : argtok->values()) {
2209 if (!v.isLifetimeValue())
2210 continue;
2211 const Token *tok3 = v.tokvalue;
2212 for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok3, settings)) {
2213 if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive)
2214 continue;
2215 if (!lt.token)
2216 return false;
2217 if (!pred(lt.token))
2218 return false;
2219 ErrorPath er = v.errorPath;
2220 er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend());
2221 er.emplace_back(argtok, message);
2222 er.insert(er.end(), errorPath.cbegin(), errorPath.cend());
2223
2224 ValueFlow::Value value;
2225 value.valueType = ValueFlow::Value::ValueType::LIFETIME;
2226 value.lifetimeScope = v.lifetimeScope;

Callers 6

byDerefCopyMethod · 0.80
valueFlowLifetimeFunction · 0.80

Calls 9

getLifetimeTokensFunction · 0.85
setSourceLocationFunction · 0.85
setTokenValueFunction · 0.85
variableMethod · 0.80
setInconclusiveMethod · 0.80
emptyMethod · 0.45
isEnabledMethod · 0.45
endMethod · 0.45
isInconclusiveMethod · 0.45

Tested by

no test coverage detected