Fix 11530: FP arrayIndexOutOfBounds with array of functions (#5191)

This commit is contained in:
Paul Fultz II 2023-06-25 13:38:44 -05:00 committed by GitHub
parent 4f466a5961
commit a2ee32695f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -796,14 +796,15 @@ struct ForwardTraversal {
return Break(); return Break();
return Break(); return Break();
} else if (Token* callTok = callExpr(tok)) { } else if (Token* callTok = callExpr(tok)) {
// TODO: Dont traverse tokens a second time
if (start != callTok && tok != callTok && updateRecursive(callTok->astOperand1()) == Progress::Break)
return Break();
// Since the call could be an unknown macro, traverse the tokens as a range instead of recursively // Since the call could be an unknown macro, traverse the tokens as a range instead of recursively
if (!Token::simpleMatch(callTok, "( )") && if (!Token::simpleMatch(callTok, "( )") &&
updateRange(callTok->next(), callTok->link(), depth - 1) == Progress::Break) updateRange(callTok->next(), callTok->link(), depth - 1) == Progress::Break)
return Break(); return Break();
if (updateTok(callTok) == Progress::Break) if (updateTok(callTok) == Progress::Break)
return Break(); return Break();
if (start != callTok && updateRecursive(callTok->astOperand1()) == Progress::Break)
return Break();
tok = callTok->link(); tok = callTok->link();
if (!tok) if (!tok)
return Break(); return Break();

View File

@ -175,6 +175,7 @@ private:
TEST_CASE(array_index_70); // #11355 TEST_CASE(array_index_70); // #11355
TEST_CASE(array_index_71); // #11461 TEST_CASE(array_index_71); // #11461
TEST_CASE(array_index_72); // #11784 TEST_CASE(array_index_72); // #11784
TEST_CASE(array_index_73); // #11530
TEST_CASE(array_index_multidim); TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for); TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_for_in_for); // FP: #2634 TEST_CASE(array_index_for_in_for); // FP: #2634
@ -1940,6 +1941,17 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
// #11530
void array_index_73()
{
check("void f() {\n"
" int k = 0;\n"
" std::function<void(int)> a[1] = {};\n"
" a[k++](0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void array_index_multidim() { void array_index_multidim() {
check("void f()\n" check("void f()\n"
"{\n" "{\n"