fix [B#2589 (segmentation fault of cppcheck (struct B : A))

This commit is contained in:
Robert Reif 2011-02-19 14:38:00 -05:00
parent caca6e94e6
commit e6eb160395
3 changed files with 21 additions and 1 deletions

View File

@ -1405,7 +1405,7 @@ void CheckBufferOverrun::checkStructVariable()
const std::string &structname = tok->next()->str();
const Token *tok2 = tok;
while (tok2->str() != "{")
while (tok2 && tok2->str() != "{")
tok2 = tok2->next();
// Found a struct declaration. Search for arrays..

View File

@ -57,6 +57,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// goto initial '{'
tok2 = initBaseInfo(new_scope, tok);
// make sure we have valid code
if (!tok2)
{
delete new_scope;
break;
}
}
new_scope->classStart = tok2;
@ -872,6 +879,10 @@ const Token *SymbolDatabase::initBaseInfo(Scope *scope, const Token *tok)
tok2 = tok2->next();
// check for invalid code
if (!tok2->next())
return NULL;
if (tok2->str() == "public")
{
base.access = Public;

View File

@ -192,6 +192,7 @@ private:
TEST_CASE(symboldatabase11); // ticket #2539
TEST_CASE(symboldatabase12); // ticket #2547
TEST_CASE(symboldatabase13); // ticket #2577
TEST_CASE(symboldatabase14); // ticket #2589
}
// Check the operator Equal
@ -5550,6 +5551,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void symboldatabase14()
{
// ticket #2589 - segmentation fault
checkConst("struct B : A\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)