fix #2603 (segmentation fault of cppcheck ( typedef constexpr))

This commit is contained in:
Robert Reif 2011-02-22 07:48:34 -05:00
parent 703448171a
commit dd12fc177f
2 changed files with 24 additions and 0 deletions

View File

@ -1039,6 +1039,13 @@ void Tokenizer::simplifyTypedef()
Token *namespaceStart = 0;
Token *namespaceEnd = 0;
// check for invalid input
if (!tok->next())
{
syntaxError(tok);
return;
}
if (Token::simpleMatch(tok->next(), "::") ||
Token::Match(tok->next(), "%type%"))
{
@ -1071,6 +1078,13 @@ void Tokenizer::simplifyTypedef()
else
continue; // invalid input
// check for invalid input
if (!tok->tokAt(offset))
{
syntaxError(tok);
return;
}
// check for template
if (tok->tokAt(offset)->str() == "<")
{

View File

@ -240,6 +240,7 @@ private:
TEST_CASE(simplifyTypedef78); // ticket #2568
TEST_CASE(simplifyTypedef79); // ticket #2348
TEST_CASE(simplifyTypedef80); // ticket #2587
TEST_CASE(simplifyTypedef81); // ticket #2603
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4921,6 +4922,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef81() // ticket #2603 segmentation fault
{
checkSimplifyTypedef("typedef\n");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
checkSimplifyTypedef("typedef constexpr\n");
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
void simplifyTypedefFunction1()
{
{