diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 90287bb39..dd6ee87eb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5528,6 +5528,9 @@ void Tokenizer::simplifyVarDecl() } } + if (!tok2) + break; + if (Token::Match(tok2, ":: %type%")) { typelen += 2; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 978ec46d7..504e1c769 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -234,7 +234,8 @@ private: TEST_CASE(vardecl_union); TEST_CASE(volatile_variables); TEST_CASE(syntax_error); - TEST_CASE(syntax_error_templates); + TEST_CASE(syntax_error_templates_1); + TEST_CASE(syntax_error_templates_2); TEST_CASE(removeKeywords); @@ -4165,7 +4166,7 @@ private: } - void syntax_error_templates() + void syntax_error_templates_1() { // ok code.. using ">" for a comparison { @@ -4235,6 +4236,14 @@ private: } } + void syntax_error_templates_2() + { + std::istringstream istr("template<>\n"); + Settings settings; + Tokenizer tokenizer(&settings, this); + tokenizer.tokenize(istr, "test.cpp"); // shouldn't segfault + } + void removeKeywords() { const char code[] = "if (__builtin_expect(!!(x), 1));";