fixed #4169 semgentation fault (invalid code); Applied patch from amai and added a unittest.
This commit is contained in:
parent
3f89e38275
commit
3905f4ad7d
|
@ -206,6 +206,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
while (Token::Match(tok, "*|&|const"))
|
while (Token::Match(tok, "*|&|const"))
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
if (!tok)
|
||||||
|
return 0;
|
||||||
|
|
||||||
// Function pointer or prototype..
|
// Function pointer or prototype..
|
||||||
while (tok->str() == "(")
|
while (tok->str() == "(")
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
|
@ -216,6 +219,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tok)
|
||||||
|
return 0;
|
||||||
// ,/>
|
// ,/>
|
||||||
while (tok->str() == ">" || tok->str() == ">>") {
|
while (tok->str() == ">" || tok->str() == ">>") {
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
|
|
||||||
// Test TemplateSimplifier::templateParameters
|
// Test TemplateSimplifier::templateParameters
|
||||||
TEST_CASE(templateParameters);
|
TEST_CASE(templateParameters);
|
||||||
|
TEST_CASE(templateParameters1); // #4169 - segmentation fault
|
||||||
|
|
||||||
TEST_CASE(namespaces);
|
TEST_CASE(namespaces);
|
||||||
|
|
||||||
|
@ -2384,6 +2385,12 @@ private:
|
||||||
ASSERT_EQUALS(1U, templateParameters("<const struct C> x;"));
|
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() {
|
void namespaces() {
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue