diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 00e1674d9..bcf8cad3a 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -344,7 +344,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f const Token* tok = tok2->astOperand1(); if (Token::Match(tok, ".|::")) tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1(); - varid = tok->varId(); + if (tok) + varid = tok->varId(); break; } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6fcc82507..6f9ce3b00 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5712,6 +5712,14 @@ private: " malloc();\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #7182 "crash: CheckMemoryLeak::functionReturnType()" + check("template auto unary_right_comma (Ts... ts) { return (ts , ...); }\n" + "template auto binary_left_comma (T x, Ts... ts) { return (x , ... , ts); }\n" + "int main() {\n" + " unary_right_comma (a);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void smartPointerFunctionParam() {