Fix crash in valueFlowForLoopSimplifyAfter (#2573)

This commit is contained in:
Paul Fultz II 2020-03-20 01:16:05 -05:00 committed by GitHub
parent cdcde7855d
commit f2527f5340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -4496,12 +4496,15 @@ static void valueFlowForLoopSimplifyAfter(Token *fortok, nonneg int varid, const
else
endToken = fortok->scope()->bodyEnd;
Token* blockTok = fortok->linkAt(1)->linkAt(1);
std::list<ValueFlow::Value> values;
values.emplace_back(num);
values.back().errorPath.emplace_back(fortok,"After for loop, " + var->name() + " has value " + values.back().infoString());
valueFlowForwardVariable(
fortok->linkAt(1)->linkAt(1)->next(), endToken, var, varid, values, false, false, tokenlist, errorLogger, settings);
if (blockTok != endToken) {
valueFlowForwardVariable(
blockTok->next(), endToken, var, varid, values, false, false, tokenlist, errorLogger, settings);
}
}
static void valueFlowForLoop(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)

View File

@ -4444,6 +4444,14 @@ private:
" return r;\n"
"}\n";
valueOfTok(code, "0");
code = "void fa(int &colors) {\n"
" for (int i = 0; i != 6; ++i) {}\n"
"}\n"
"void fb(not_null<int*> parent, int &&colors2) {\n"
" dostuff(1);\n"
"}\n";
valueOfTok(code, "x");
}
void valueFlowCrashConstructorInitialization() { // #9577