fix #2651 (Segmentation fault (typedef))

This commit is contained in:
Robert Reif 2011-03-17 20:00:49 -04:00
parent f191b854c2
commit 7b63da4964
2 changed files with 25 additions and 3 deletions

View File

@ -1235,15 +1235,24 @@ void Tokenizer::simplifyTypedef()
// function: typedef ... ( .... type )( ... );
// typedef ... (( .... type )( ... ));
// typedef ... ( * ( .... type )( ... ));
else if ((tok->tokAt(offset)->str() == "(" &&
Token::Match(tok->tokAt(offset)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset)->link()->next()->link(), ") const|volatile|;")) ||
(Token::simpleMatch(tok->tokAt(offset), "( (") &&
Token::Match(tok->tokAt(offset + 1)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset + 1)->link()->next()->link(), ") const|volatile| )")))
Token::Match(tok->tokAt(offset + 1)->link()->next()->link(), ") const|volatile| ) ;|,")) ||
(Token::simpleMatch(tok->tokAt(offset), "( * (") &&
Token::Match(tok->tokAt(offset + 2)->link()->previous(), "%type% ) (") &&
Token::Match(tok->tokAt(offset + 2)->link()->next()->link(), ") const|volatile| ) ;|,")))
{
if (tok->strAt(offset + 1) == "(")
offset++;
else if (Token::simpleMatch(tok->tokAt(offset), "( * ("))
{
pointers.push_back("*");
offset += 2;
}
if (tok->tokAt(offset)->link()->strAt(-2) == "*")
functionPtr = true;
@ -1289,7 +1298,9 @@ void Tokenizer::simplifyTypedef()
}
// pointer to function returning pointer to function
else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) ("))
else if (Token::Match(tok->tokAt(offset), "( * ( * %type% ) (") &&
Token::Match(tok->tokAt(offset + 6)->link(), ") ) (") &&
Token::Match(tok->tokAt(offset + 6)->link()->tokAt(2)->link(), ") ;|,"))
{
functionPtrRetFuncPtr = true;
@ -1305,7 +1316,8 @@ void Tokenizer::simplifyTypedef()
// function returning pointer to function
else if (Token::Match(tok->tokAt(offset), "( * %type% (") &&
Token::simpleMatch(tok->tokAt(offset + 3)->link(), ") ) ("))
Token::simpleMatch(tok->tokAt(offset + 3)->link(), ") ) (") &&
Token::Match(tok->tokAt(offset + 3)->link()->tokAt(2)->link(), ") ;|,"))
{
functionRetFuncPtr = true;

View File

@ -250,6 +250,7 @@ private:
TEST_CASE(simplifyTypedef84); // ticket #2630
TEST_CASE(simplifyTypedef85); // ticket #2651
TEST_CASE(simplifyTypedef86); // ticket #2581
TEST_CASE(simplifyTypedef87); // ticket #2651
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -5060,6 +5061,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef87() // ticket #2651
{
const char code[] = "typedef FOO (*(*BAR)(void, int, const int, int*));\n";
const char expected[] = ";";
checkSimplifyTypedef(code);
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{