From 5d6a257c86af7ea16cc866a26be80212d8fc6a16 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sun, 29 Apr 2012 12:58:12 +0200 Subject: [PATCH] Fixed #3770 (Segmentation fault in K&R function parameters simplification) --- lib/tokenize.cpp | 4 ++++ test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ea340dfdc..8213961a2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4830,6 +4830,10 @@ bool Tokenizer::simplifyFunctionParameters() std::map argumentNames2; while (tok1 && tok1->str() != "{") { + if (tok1->str() == "(" || tok1->str() == ")") { + bailOut = true; + break; + } if (tok1->str() == ";") { if (tokparam) { syntaxError(tokparam); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index ed2cb3fa6..679485714 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4157,6 +4157,19 @@ private: "}"; ASSERT_EQUALS("void foo ( ) { if ( x ) { } { } }", tokenizeAndStringify(code, true)); } + + // #3770 - Don't segfault and don't change macro argument as if it's a K&R function argument + { + const char code[] = "MACRO(a)" + "" + "void f()" + "{" + " SetLanguage();" + " {" + " }" + "}"; + ASSERT_EQUALS("MACRO ( a ) void f ( ) { SetLanguage ( ) ; { } }", tokenizeAndStringify(code, true)); + } } void simplifyFunctionParameters1() { // ticket #3721