Skip to content

Commit 7d4276c

Browse files
committed
(int) is not lambda call
1 parent 2621d76 commit 7d4276c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkleakautovar.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,17 @@ static const Token * isFunctionCall(const Token * nameToken)
282282
static const Token * isAnonymousFunctionCall(const Token * tok)
283283
{
284284
// match one of the supported LHS patterns
285-
if (tok->previous()->str() == "(" && !tok->previous()->isBinaryOp() && tok->linkAt(-1)) {
285+
// TODO: check if tok->previous()->isCast(). can't right now because
286+
//
287+
// auto x = [](void *ptr) { g(ptr) };
288+
// void *p = malloc(1);
289+
// (x)(p);
290+
// ^
291+
// the lpar surrounding x has isCast() == true, so checking isCast() would
292+
// have false positive leaks, while allowing casts to take ownership of
293+
// resources is instead a false negative
294+
if (tok->previous()->str() == "(" && !tok->previous()->isBinaryOp() &&
295+
tok->linkAt(-1) && !tok->isStandardType()) {
286296
tok = tok->linkAt(-1)->next();
287297
} else if (!tok->isStandardType() && tok->isName() && tok->linkAt(1)) {
288298
tok = tok->linkAt(1)->next();

0 commit comments

Comments
 (0)