From 3d4eb0d77ed292854131f1d981afcaa32c492564 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 10 Jun 2011 15:11:45 -0400 Subject: [PATCH] fix #2682 (segmentation fault of cppcheck ( x a[0] = )) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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()); } };