From 7c7ee66cf929f6fe7658550f695f6fe477011763 Mon Sep 17 00:00:00 2001 From: Pavol Misik Date: Sat, 23 Mar 2019 10:42:41 +0100 Subject: [PATCH] Fix crash in TemplateSimplifier::TokenAndName::TokenAndName in case of template constexpr (#1748) This is not propper solution. This change just eliminates crash and logs error. https://trac.cppcheck.net/ticket/9046 --- lib/templatesimplifier.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 46717e796..43e749027 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -83,8 +83,13 @@ TemplateSimplifier::TokenAndName::TokenAndName(Token *tok, const std::string &s, isAlias(paramEnd->strAt(1) == "using"); isClass(Token::Match(paramEnd->next(), "class|struct|union %name% <|{|:|;")); const Token *tok1 = nameToken->next(); - if (tok1->str() == "<") - tok1 = tok1->findClosingBracket()->next(); + if (tok1->str() == "<") { + const Token *closing = tok1->findClosingBracket(); + if (closing) + tok1 = closing->next(); + else + throw InternalError(tok, "unsupported syntax", InternalError::SYNTAX); + } isFunction(tok1->str() == "("); isVariable(!isClass() && Token::Match(tok1, "=|;")); if (isVariable())