From d678e4424c7dfea1ab87ef3a898dd616317eb1af Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 6 Mar 2011 18:59:56 -0500 Subject: [PATCH] fix #2630 (segmentation fault of cppcheck ( typedef y x () x )) --- lib/tokenize.cpp | 19 ++++++++----------- test/testsimplifytokens.cpp | 8 ++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c028b3388..38d948075 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1185,19 +1185,16 @@ void Tokenizer::simplifyTypedef() tok = deleteInvalidTypedef(typeDef); continue; } + else if (!Token::Match(tok->tokAt(offset)->link(), ") ;|,")) + { + syntaxError(tok); + return; + } function = true; - if (tok->tokAt(offset)->link()->next()) - { - argStart = tok->tokAt(offset); - argEnd = tok->tokAt(offset)->link(); - tok = argEnd->next(); - } - else - { - // internal error - continue; - } + argStart = tok->tokAt(offset); + argEnd = tok->tokAt(offset)->link(); + tok = argEnd->next(); } // unhandled typedef, skip it and continue diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 37f484c6b..e0f6d3499 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -245,6 +245,7 @@ private: TEST_CASE(simplifyTypedef81); // ticket #2603 TEST_CASE(simplifyTypedef82); // ticket #2403 TEST_CASE(simplifyTypedef83); // ticket #2620 + TEST_CASE(simplifyTypedef84); // ticket #2630 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4975,6 +4976,13 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void simplifyTypedef84() // ticket #2630 (segmentation fault) + { + const char code[] = "typedef y x () x\n"; + checkSimplifyTypedef(code); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } + void simplifyTypedefFunction1() { {