fixed #4169 semgentation fault (invalid code); Applied patch from amai and added a unittest.

This commit is contained in:
Ettl Martin 2012-09-19 11:03:40 +02:00
parent 3f89e38275
commit 3905f4ad7d
2 changed files with 12 additions and 0 deletions

View File

@ -206,6 +206,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
while (Token::Match(tok, "*|&|const"))
tok = tok->next();
if (!tok)
return 0;
// Function pointer or prototype..
while (tok->str() == "(")
tok = tok->link()->next();
@ -216,6 +219,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
tok = tok->next();
}
if (!tok)
return 0;
// ,/>
while (tok->str() == ">" || tok->str() == ">>") {
if (level == 0)

View File

@ -134,6 +134,7 @@ private:
// Test TemplateSimplifier::templateParameters
TEST_CASE(templateParameters);
TEST_CASE(templateParameters1); // #4169 - segmentation fault
TEST_CASE(namespaces);
@ -2384,6 +2385,12 @@ private:
ASSERT_EQUALS(1U, templateParameters("<const struct C> x;"));
}
void templateParameters1() {
// #4169 - semgentation fault (invalid code)
const char code[] = "volatile true , test < test < #ifdef __ppc__ true ,";
// do not crash on invalid code
ASSERT_EQUALS(0, templateParameters(code));
}
void namespaces() {
{