Fixed #2221 (segmentation fault of cppcheck)

This commit is contained in:
Robert Reif 2010-11-23 07:31:15 +01:00 committed by Daniel Marjamäki
parent a16c0dbd5e
commit f1eef49fcb
2 changed files with 35 additions and 5 deletions

View File

@ -872,7 +872,7 @@ void SymbolDatabase::SpaceInfo::getVarList()
if (!tok->isStandardType())
isClass = true;
vartok = tok->tokAt(1);
vartok = tok->next();
tok = vartok->next();
}
else if (Token::Match(tok, "%type% :: %type% %var% ;"))
@ -923,7 +923,7 @@ void SymbolDatabase::SpaceInfo::getVarList()
if (!tok->isStandardType())
isClass = true;
vartok = tok->tokAt(1);
vartok = tok->next();
tok = vartok->next()->link()->next();
}
@ -948,6 +948,10 @@ void SymbolDatabase::SpaceInfo::getVarList()
else if (Token::Match(tok, "%type% :: %type% <") ||
Token::Match(tok, "%type% <"))
{
// got an unhandled template?
if (tok->str() == "template")
continue;
// find matching ">"
int level = 0;
for (; tok; tok = tok->next())
@ -960,14 +964,26 @@ void SymbolDatabase::SpaceInfo::getVarList()
if (level == 0)
break;
}
else if (tok->str() == ">>")
{
level-=2;
if (level <= 0)
break;
}
if (tok && Token::Match(tok, "> %var% ;"))
else if (tok->str() == "(")
tok = tok->link();
// don't crash on unhandled templates
if (tok->next() == NULL)
break;
}
if (tok && (Token::Match(tok, "> %var% ;") || Token::Match(tok, ">> %var% ;")))
{
isClass = true;
vartok = tok->tokAt(1);
vartok = tok->next();
tok = vartok->next();
}
else if (tok && Token::Match(tok, "> * %var% ;"))
else if (tok && (Token::Match(tok, "> * %var% ;") || Token::Match(tok, ">> * %var% ;")))
{
vartok = tok->tokAt(2);
tok = vartok->next();

View File

@ -169,6 +169,7 @@ private:
TEST_CASE(symboldatabase3); // ticket #2000
TEST_CASE(symboldatabase4);
TEST_CASE(symboldatabase5); // ticket #2178
TEST_CASE(symboldatabase6); // ticket #2221
}
// Check the operator Equal
@ -4827,6 +4828,19 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
void symboldatabase6()
{
// ticket #2221 - segmentation fault
checkConst("template<int i> class X { };\n"
"X< 1>2 > x1;\n"
"X<(1>2)> x2;\n"
"template<class T> class Y { };\n"
"Y<X<1>> x3;\n"
"Y<X<6>>1>> x4;\n"
"Y<X<(6>>1)>> x5;\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)