Skip to content

Commit

Permalink
Fix 11530: FP arrayIndexOutOfBounds with array of functions (danmar#5191
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pfultz2 committed Jun 25, 2023
1 parent 4f466a5 commit a2ee326
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,14 +796,15 @@ struct ForwardTraversal {
return Break();
return Break();
} 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
if (!Token::simpleMatch(callTok, "( )") &&
updateRange(callTok->next(), callTok->link(), depth - 1) == Progress::Break)
return Break();
if (updateTok(callTok) == Progress::Break)
return Break();
if (start != callTok && updateRecursive(callTok->astOperand1()) == Progress::Break)
return Break();
tok = callTok->link();
if (!tok)
return Break();
Expand Down
12 changes: 12 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class TestBufferOverrun : public TestFixture {
TEST_CASE(array_index_70); // #11355
TEST_CASE(array_index_71); // #11461
TEST_CASE(array_index_72); // #11784
TEST_CASE(array_index_73); // #11530
TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_for_in_for); // FP: #2634
Expand Down Expand Up @@ -1940,6 +1941,17 @@ class TestBufferOverrun : public TestFixture {
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() {
check("void f()\n"
"{\n"
Expand Down

0 comments on commit a2ee326

Please sign in to comment.