fix #2886 (crash of cppcheck ( typedef struct x { } ))

This commit is contained in:
Robert Reif 2011-07-03 10:50:15 -04:00
parent 8ec1dfacbf
commit b143b283e9
2 changed files with 9 additions and 1 deletions

View File

@ -898,7 +898,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
tok1->insertToken(";");
tok1 = tok1->next();
if (tok1->next()->str() == ";" && tok1 && tok1->previous()->str() == "}")
if (tok1->next() && tok1->next()->str() == ";" && tok1 && tok1->previous()->str() == "}")
{
tok->deleteThis();
tok1->deleteThis();

View File

@ -260,6 +260,7 @@ private:
TEST_CASE(simplifyTypedef93); // ticket #2738
TEST_CASE(simplifyTypedef94); // ticket #1982
TEST_CASE(simplifyTypedef95); // ticket #2844
TEST_CASE(simplifyTypedef96); // ticket #2886
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -5374,6 +5375,13 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef96() // ticket #2886 (segmentation fault)
{
const char code[] = "typedef struct x { }\n";
sizeof_(code);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
void simplifyTypedefFunction1()
{
{