From cf3ab649fb4cdc37c7ec767130e4f13106c87e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 16 Jul 2011 19:26:11 +0200 Subject: [PATCH] Fixed #2873 (segmentation fault of cppcheck while scanning rose-compiler suite) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b38d22f33..03473f68f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4962,7 +4962,7 @@ bool Tokenizer::simplifyIfAddBraces() { for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) { - if (tok->str() == "(") + if (tok->str() == "(" && !Token::Match(tok->previous(), "[;{}]")) { tok = tok->link(); continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9bb27e51d..7557f396d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5705,6 +5705,15 @@ private: { tokenizeAndStringify("if()x"); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + + // ticket #2873 + { + const char code[] = "void f() { " + "( { if(*p) (*p) = x(); } ) " + "}"; + ASSERT_EQUALS("void f ( ) { ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }", + tokenizeAndStringify(code)); + } } };