Fixed #4442 (crash of cppcheck while scanning gcc-testsuite (invalid code))

This commit is contained in:
Robert Reif 2012-12-28 08:36:20 +01:00 committed by Daniel Marjamäki
parent b914466285
commit bd2f59bdf0
3 changed files with 11 additions and 2 deletions

View File

@ -366,7 +366,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
if (level == 0 && Token::Match(ftok, "%var% (")) {
if (ftok->strAt(2) != ")")
initVar(ftok->str(), scope, usage);
} else if (level == 0 && Token::Match(ftok, "%var% {") && ftok->str() != "const") {
} else if (level == 0 && Token::Match(ftok, "%var% {") && ftok->str() != "const" && Token::Match(ftok->next()->link()->next(), ",|{|%name%")) {
initVar(ftok->str(), scope, usage);
ftok = ftok->linkAt(1);
} else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x)

View File

@ -1258,7 +1258,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
Scope *new_scope = &scopeList.back();
// skip to start of function
while (tok1 && ((tok1->str() != "{") || (tok1->previous() && tok1->previous()->isName() && tok1->strAt(-1) != "const"))) {
while (tok1 && ((tok1->str() != "{") || (tok1->previous() && tok1->previous()->isName() && tok1->strAt(-1) != "const" && Token::Match(tok1->link()->next(), ",|{|%name%")))) {
if (tok1->str() == "(" || tok1->str() == "{")
tok1 = tok1->link();
tok1 = tok1->next();

View File

@ -154,6 +154,7 @@ private:
TEST_CASE(symboldatabase26); // ticket #3561 (throw C)
TEST_CASE(symboldatabase27); // ticket #3543 (segmentation fault)
TEST_CASE(symboldatabase28);
TEST_CASE(symboldatabase29); // ticket #4442 (segmentation fault)
TEST_CASE(isImplicitlyVirtual);
@ -1324,6 +1325,14 @@ private:
ASSERT(db && db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->type() && db->getVariableFromVarId(1)->type()->className == "S");
}
// #ticket #4442 (segmentation fault)
void symboldatabase29() {
check("struct B : A {\n"
" B() : A {}\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void isImplicitlyVirtual() {
{
GET_SYMBOL_DB("class Base {\n"