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

Function valueFlowForLoopSimplifyAfter

lib/valueflow.cpp:5332–5358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5330}
5331
5332static void valueFlowForLoopSimplifyAfter(Token* fortok, nonneg int varid, const MathLib::bigint num, const TokenList& tokenlist, ErrorLogger & errorLogger, const Settings& settings)
5333{
5334 const Token *vartok = nullptr;
5335 for (const Token *tok = fortok; tok; tok = tok->next()) {
5336 if (tok->varId() == varid) {
5337 vartok = tok;
5338 break;
5339 }
5340 }
5341 if (!vartok || !vartok->variable())
5342 return;
5343
5344 const Variable *var = vartok->variable();
5345 const Token *endToken = nullptr;
5346 if (var->isLocal())
5347 endToken = var->scope()->bodyEnd;
5348 else
5349 endToken = fortok->scope()->bodyEnd;
5350
5351 Token* blockTok = fortok->linkAt(1)->linkAt(1);
5352 if (blockTok != endToken) {
5353 ValueFlow::Value v{num};
5354 v.errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + v.infoString());
5355
5356 valueFlowForward(blockTok->next(), endToken, vartok, std::move(v), tokenlist, errorLogger, settings);
5357 }
5358}
5359
5360static void valueFlowForLoop(const TokenList &tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
5361{

Callers 1

valueFlowForLoopFunction · 0.85

Calls 7

valueFlowForwardFunction · 0.85
nextMethod · 0.80
variableMethod · 0.80
scopeMethod · 0.80
linkAtMethod · 0.80
infoStringMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected