From 708a75e36330d0f8d329c6a7ddb3bf1008eda1b5 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 14 Jan 2011 07:41:22 +0100 Subject: [PATCH] Fixed #2452 (syntax error when 'void f(typedef int x)' is used. causes segmentation fault.) --- lib/tokenize.cpp | 7 +++++++ test/testsimplifytokens.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0b31557d2..5d6117132 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -856,6 +856,13 @@ void Tokenizer::simplifyTypedef() else if (tok->str() != "typedef") continue; + // check for syntax errors + if (tok->previous() && tok->previous()->str() == "(") + { + syntaxError(tok); + continue; + } + // pull struct, union, enum or class definition out of typedef // use typedef name for unnamed struct, union, enum or class if (Token::Match(tok->next(), "const| struct|enum|union|class %type% {") || diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 17e6e6c7b..0723e03af 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -233,6 +233,7 @@ private: TEST_CASE(simplifyTypedef73); // ticket #2412 TEST_CASE(simplifyTypedef74); // ticket #2414 TEST_CASE(simplifyTypedef75); // ticket #2426 + TEST_CASE(simplifyTypedef76); // ticket #2453 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4795,6 +4796,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef76() // ticket #2453 segmentation fault + { + const char code[] = "void f1(typedef int x) {}\n"; + const std::string expected = "void f1 ( typedef int x ) { }"; + ASSERT_EQUALS(expected, sizeof_(code)); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } + void simplifyTypedefFunction1() { {