Fix #2579 (segmentation fault of cppcheck)

This commit is contained in:
Robert Reif 2011-02-13 14:11:22 -05:00
parent ad22aebf8c
commit c03ace7378
2 changed files with 11 additions and 3 deletions

View File

@ -8748,7 +8748,7 @@ void Tokenizer::simplifyStructDecl()
}
// unnamed anonymous struct/union so remove it
else if (tok->next()->str() == ";")
else if (tok->next() && tok->next()->str() == ";")
{
if (tok1->str() == "union")
{

View File

@ -304,7 +304,8 @@ private:
TEST_CASE(initstruct);
// struct ABC { } abc; => struct ABC { }; ABC abc;
TEST_CASE(simplifyStructDecl);
TEST_CASE(simplifyStructDecl1);
TEST_CASE(simplifyStructDecl2); // ticket #2579
// register int var; => int var;
// inline int foo() {} => int foo() {}
@ -6222,7 +6223,7 @@ private:
tok("; struct A a = { .buf = {0} };"));
}
void simplifyStructDecl()
void simplifyStructDecl1()
{
{
const char code[] = "struct ABC { } abc;";
@ -6365,6 +6366,13 @@ private:
}
}
void simplifyStructDecl2() // ticket #2479 (segmentation fault)
{
const char code[] = "struct { char c; }";
const char expected[] = "struct { char c ; }";
ASSERT_EQUALS(expected, tok(code, false));
}
void removeUnwantedKeywords()
{
ASSERT_EQUALS("int var ;", tok("register int var ;", true));