diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 43181c115..5e4270b08 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5877,7 +5877,7 @@ void Tokenizer::simplifyVarDecl() tok2 = tok2->next(); - if (tok2->str() == ";") + if (tok2 && tok2->str() == ";") tok2 = NULL; } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 3b2542c72..88efac783 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -352,6 +352,7 @@ private: TEST_CASE(removeUnnecessaryQualification2); TEST_CASE(simplifyIfNotNull); + TEST_CASE(simplifyVarDecl); // ticket # 2682 segmentation fault } std::string tok(const char code[], bool simplify = true) @@ -6983,7 +6984,13 @@ private: "}"; ASSERT_EQUALS("void f ( int x ) { }", tok(code, false)); } + } + void simplifyVarDecl() // ticket # 2682 segmentation fault + { + const char code[] = "x a[0] ="; + tok(code, false); + ASSERT_EQUALS("", errout.str()); } };