Skip to content

Commit a0fa6fb

Browse files
committed
call to array element
1 parent cd4f032 commit a0fa6fb

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎lib/checkleakautovar.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ static const Token * isFunctionCall(const Token * nameToken)
275275
* (lambda)(arg)
276276
* or
277277
* get_function()(arg)
278-
*
278+
* or
279+
* arr[idx](arg)
279280
* @param tok on the LHS of a function call
280281
* @return opening parenthesis token or nullptr if not a function call
281282
*/
@@ -291,7 +292,7 @@ static const Token *isAnonymousFunctionCall(const Token *tok)
291292
// function pointer or lambda
292293
if (isLparNotCast(tok->previous())) {
293294
tok = tok->linkAt(-1)->next();
294-
} else if (tok->isName() && isLparNotCast(tok->next())) {
295+
} else if (tok->isName() && (isLparNotCast(tok->next()) || tok->strAt(1) == "[")) {
295296
// call to result of a function
296297
tok = tok->linkAt(1)->next();
297298
} else {

‎test/testleakautovar.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,13 @@ class TestLeakAutoVar : public TestFixture {
19341934
"}\n");
19351935
ASSERT_EQUALS("", errout_str());
19361936

1937+
// Array of function pointers
1938+
check("void f() {\n"
1939+
" void *buf = malloc(1);\n"
1940+
" arr[0](buf);\n"
1941+
"}\n");
1942+
ASSERT_EQUALS("", errout_str());
1943+
19371944
// Function returning a function pointer, passed as an arg to a normal
19381945
// function
19391946
check("void f() {\n"

0 commit comments

Comments
 (0)