diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 82edace95..06353a96d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5931,7 +5931,7 @@ void Tokenizer::simplifyVarDecl() } } - if (!tok2) + if (!tok2) // syntax error break; if (Token::Match(tok2, ":: %type%")) @@ -5940,6 +5940,9 @@ void Tokenizer::simplifyVarDecl() tok2 = tok2->tokAt(2); } + if (!tok2) // syntax error + break; + if (tok2->str() == "*") { tok2 = tok2->next(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 88efac783..16431ed86 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -352,7 +352,8 @@ private: TEST_CASE(removeUnnecessaryQualification2); TEST_CASE(simplifyIfNotNull); - TEST_CASE(simplifyVarDecl); // ticket # 2682 segmentation fault + TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault + TEST_CASE(simplifyVarDecl2); // ticket # 2834 segmentation fault } std::string tok(const char code[], bool simplify = true) @@ -6986,12 +6987,19 @@ private: } } - void simplifyVarDecl() // ticket # 2682 segmentation fault + void simplifyVarDecl1() // ticket # 2682 segmentation fault { const char code[] = "x a[0] ="; tok(code, false); ASSERT_EQUALS("", errout.str()); } + + void simplifyVarDecl2() // ticket # 2834 segmentation fault + { + const char code[] = "std::vector::iterator"; + tok(code, false); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestSimplifyTokens)