fix [B#2589 (segmentation fault of cppcheck (struct B : A))
This commit is contained in:
parent
caca6e94e6
commit
e6eb160395
|
@ -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..
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue