Fix 10338: Hang/Crash in valueflow (#3328)

This commit is contained in:
Paul Fultz II 2021-07-07 01:20:32 -05:00 committed by GitHub
parent 81eabb5f61
commit 3b9c399f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -597,7 +597,7 @@ bool precedes(const Token * tok1, const Token * tok2)
if (!tok1)
return false;
if (!tok2)
return false;
return true;
return tok1->index() < tok2->index();
}

View File

@ -471,7 +471,7 @@ struct ForwardTraversal {
if (depth < 0)
return Break(Analyzer::Terminate::Bail);
std::size_t i = 0;
for (Token* tok = start; tok && tok != end; tok = tok->next()) {
for (Token* tok = start; precedes(tok, end); tok = tok->next()) {
Token* next = nullptr;
if (tok->index() <= i)
throw InternalError(tok, "Cyclic forward analysis.");

View File

@ -5630,6 +5630,15 @@ private:
" return e;\n"
"}\n";
valueOfTok(code, "x");
code = "void a() {\n"
" int b = 0;\n"
" do {\n"
" for (;;)\n"
" break;\n"
" } while (b < 1);\n"
"}\n";
valueOfTok(code, "b");
}
void valueFlowCrashConstructorInitialization() { // #9577