From c337b4eb33ec490df23fe851e092e9cb3a4a9bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 12 Nov 2009 18:53:26 +0100 Subject: [PATCH] Fixed #950 (Bug in cppcheck tokenize.cpp) --- lib/tokenize.cpp | 2 ++ test/testtokenize.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index be5b04ee2..47d1637d4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4609,6 +4609,8 @@ void Tokenizer::simplifyComparisonOrder() { if (Token::Match(tok, "[;(] %any% >|>= %any% [);]")) { + if (!tok->next()->isName() && !tok->next()->isNumber()) + continue; const std::string op1(tok->strAt(1)); tok->next()->str(tok->strAt(3)); tok->tokAt(3)->str(op1); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6a1108aac..a4a54fb87 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -39,6 +39,8 @@ private: void run() { + TEST_CASE(tokenize1); + TEST_CASE(minus); TEST_CASE(longtok); @@ -210,6 +212,13 @@ private: } + void tokenize1() + { + const std::string code("void f ( )\n" + "{ if ( p . y ( ) > yof ) { } }"); + ASSERT_EQUALS(code, tokenizeAndStringify(code.c_str())); + } + void minus() { ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));