From a919f4541a9ccd295b98ba40a36e530abeca20c2 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 26 Sep 2009 17:02:13 +0700 Subject: [PATCH] Fixed #732 (Tokenizer: Incorrect simplification) Regression since 58a9e05697b4585883bbc00153d1584d9247190f commit. http://sourceforge.net/apps/trac/cppcheck/ticket/732 --- src/tokenize.cpp | 4 ++++ test/testtokenize.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 67cedc1ea..0d06ca7e3 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2570,7 +2570,11 @@ void Tokenizer::simplifyVarDecl() { if (tok2->str() == "{") tok2 = tok2->link(); + tok2 = tok2->next(); + + if (tok2->str() == ";") + tok2 = NULL; } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1671fac8f..42bd16258 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -142,6 +142,7 @@ private: TEST_CASE(vardecl7); TEST_CASE(vardecl8); TEST_CASE(vardecl9); + TEST_CASE(vardecl10); TEST_CASE(vardecl_stl); TEST_CASE(volatile_variables); TEST_CASE(syntax_error); @@ -2289,6 +2290,14 @@ private: ASSERT_EQUALS(res, tokenizeAndStringify(code)); } + void vardecl10() + { + // ticket #732 + const char code[] = "char a [ 2 ] = { '-' } ; memset ( a , '-' , sizeof ( a ) ) ;"; + + ASSERT_EQUALS(code, tokenizeAndStringify(code)); + } + void volatile_variables() { const char code[] = "volatile int a=0;\n"