Fixed #1232 (segmentation fault of cppcheck when scanning templates)

This commit is contained in:
Robert Reif 2010-01-07 18:09:35 +01:00 committed by Daniel Marjamäki
parent b366dba682
commit b30b07beee
2 changed files with 29 additions and 1 deletions

View File

@ -502,7 +502,7 @@ void Tokenizer::simplifyTypedef()
level++;
}
if (Token::Match(end->next(), "%type% ;"))
if (end && end->next() && Token::Match(end->next(), "%type% ;"))
{
typeName = end->strAt(1);
tok = end->tokAt(2);

View File

@ -144,6 +144,7 @@ private:
TEST_CASE(simplifyTypedef7);
TEST_CASE(simplifyTypedef8);
TEST_CASE(simplifyTypedef9);
TEST_CASE(simplifyTypedef10);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -2372,6 +2373,33 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef10()
{
// ticket # 1232
const char code[] = "template <typename F, unsigned int N> struct E"
"{"
" typedef E<F,(N>0)?(N-1):0> v;"
" typedef typename add<v,v>::val val;"
" FP_M(val);"
"};"
"template <typename F> struct E <F,0>"
"{"
" typedef typename D<1>::val val;"
" FP_M(val);"
"};";
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
tokenizer.simplifyTokenList();
ASSERT_EQUALS("", errout.str());
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));