From 3fe1b50e60b5f4858a3a15a5492c0fdae551127c Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 31 May 2009 15:55:06 +0300 Subject: [PATCH] Fix ticket #344 (Tokenizer crash in Windows) http://apps.sourceforge.net/trac/cppcheck/ticket/344 --- src/tokenize.cpp | 9 --------- test/testtokenize.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 1a9e9fd3b..b958339bd 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2458,15 +2458,6 @@ bool Tokenizer::simplifyRedundantParanthesis() tok->deleteNext(); ret = true; } - - if (Token::Match(tok, "( %bool% ) )") || - Token::Match(tok, "( %num% ) )")) - { - tok = tok->next(); - tok->deleteNext(); - tok->previous()->deleteThis(); - ret = true; - } } return ret; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4e27158c6..3771c37c0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1652,6 +1652,25 @@ private: ostr << " " << tok->str(); ASSERT_EQUALS(std::string(" void foo ( ) { { } }"), ostr.str()); } + + { + const char code[] = "void foo()\n" + "{\n" + " if( g(10)){}\n" + "}"; + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + tokenizer.simplifyTokenList(); + + std::ostringstream ostr; + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) + ostr << " " << tok->str(); + ASSERT_EQUALS(std::string(" void foo ( ) { if ( g ( 10 ) ) { } }"), ostr.str()); + } } void simplify_numeric_condition()