fix #2630 (segmentation fault of cppcheck ( typedef ... )

This commit is contained in:
Robert Reif 2011-03-08 20:24:57 -05:00
parent c457179ce6
commit 7a7257f200
2 changed files with 17 additions and 2 deletions

View File

@ -1151,6 +1151,13 @@ void Tokenizer::simplifyTypedef()
while (Token::Match(tok->tokAt(offset), "*|&|const"))
pointers.push_back(tok->tokAt(offset++)->str());
// check for invalid input
if (!tok->tokAt(offset))
{
syntaxError(tok);
return;
}
if (Token::Match(tok->tokAt(offset), "%type%"))
{
// found the type name

View File

@ -4973,8 +4973,16 @@ private:
void simplifyTypedef84() // ticket #2630 (segmentation fault)
{
const char code[] = "typedef y x () x\n";
checkSimplifyTypedef(code);
const char code1[] = "typedef y x () x\n";
checkSimplifyTypedef(code1);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
const char code2[] = "typedef struct template <>\n";
checkSimplifyTypedef(code2);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
const char code3[] = "typedef ::<>\n";
checkSimplifyTypedef(code3);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}