From 33f728df14a7005b3e0b9bc5de7952fecf23293b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 23 May 2023 06:26:22 +0200 Subject: [PATCH] Fix #11725 Hang in simplifyTypedef() with extra parentheses (#5078) * Fix #11725 Hang in simplifyTypedef() with extra parentheses * Amend test --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 163fef002..e27b76f0d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -695,7 +695,7 @@ namespace { mRangeAfterVar.second = mEndToken; return; } - if (Token::Match(type, "%name% (") && Token::simpleMatch(type->linkAt(1), ") ;") && !type->isStandardType()) { + if (Token::Match(type, "%name% ( !!(") && Token::simpleMatch(type->linkAt(1), ") ;") && !type->isStandardType()) { mNameToken = type; mEndToken = type->linkAt(1)->next(); mRangeType.first = start; diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index bc8d46a3a..dbd428f99 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -65,6 +65,7 @@ private: TEST_CASE(cfp4); TEST_CASE(cfp5); TEST_CASE(cfp6); + TEST_CASE(cfp7); TEST_CASE(carray1); TEST_CASE(carray2); TEST_CASE(cdonotreplace1); @@ -438,6 +439,13 @@ private: ASSERT_EQUALS("void ( * a [ 10 ] ) ( void ) ;", simplifyTypedef(code)); } + void cfp7() { + const char code[] = "typedef uint32_t ((*fp)(uint32_t n));\n" // #11725 + "uint32_t g();\n" + "fp f;\n"; + ASSERT_EQUALS("uint32_t g ( ) ; uint32_t ( * f ) ( uint32_t n ) ;", simplifyTypedef(code)); + } + void carray1() { const char code[] = "typedef int t[20];\n" "t x;";