Fix #11725 Hang in simplifyTypedef() with extra parentheses (#5078)

* Fix  #11725 Hang in simplifyTypedef() with extra parentheses

* Amend test
This commit is contained in:
chrchr-github 2023-05-23 06:26:22 +02:00 committed by GitHub
parent 00733893e0
commit 33f728df14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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;";