Skip to content

Commit 86c9387

Browse files
committed
cppcheck-opensource#7182 crash: CheckMemoryLeak::functionReturnType()
1 parent 246147c commit 86c9387

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
344344
const Token* tok = tok2->astOperand1();
345345
if (Token::Match(tok, ".|::"))
346346
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
347-
varid = tok->varId();
347+
if (tok)
348+
varid = tok->varId();
348349
break;
349350
}
350351
}

test/testmemleak.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5712,6 +5712,14 @@ class TestMemleakNoVar : public TestFixture {
57125712
" malloc();\n"
57135713
"}");
57145714
ASSERT_EQUALS("", errout.str());
5715+
5716+
// #7182 "crash: CheckMemoryLeak::functionReturnType()"
5717+
check("template<typename... Ts> auto unary_right_comma (Ts... ts) { return (ts , ...); }\n"
5718+
"template<typename T, typename... Ts> auto binary_left_comma (T x, Ts... ts) { return (x , ... , ts); }\n"
5719+
"int main() {\n"
5720+
" unary_right_comma (a);\n"
5721+
"}");
5722+
ASSERT_EQUALS("", errout.str());
57155723
}
57165724

57175725
void smartPointerFunctionParam() {

0 commit comments

Comments
 (0)