Fixed #3504 (segmentation fault of cppcheck)

This commit is contained in:
Daniel Marjamäki 2012-01-13 07:57:12 +01:00
parent 47716ee4ca
commit 0648b3ed5e
2 changed files with 18 additions and 2 deletions

View File

@ -240,6 +240,9 @@ void TemplateSimplifier::removeTemplates(Token *tok)
if (tok2->str() == "(") {
tok2 = tok2->link();
} else if (tok2->str() == ")") { // garbage code! (#3504)
Token::eraseTokens(tok,tok2);
tok->deleteThis();
}
else if (tok2->str() == "{") {

View File

@ -57,7 +57,8 @@ private:
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax);
TEST_CASE(wrong_syntax1);
TEST_CASE(wrong_syntax2);
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO()
TEST_CASE(minus);
@ -617,7 +618,7 @@ private:
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
}
void wrong_syntax() {
void wrong_syntax1() {
{
errout.str("");
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
@ -648,6 +649,18 @@ private:
}
}
void wrong_syntax2() { // #3504
const char code[] = "void f() {\n"
" X<int> x;\n"
" Y<int, int, int, int, int, char> y;\n"
"}\n"
"\n"
"void G( template <typename T> class (j) ) {}";
// don't segfault..
tokenizeAndStringify(code);
}
void wrong_syntax_if_macro() {
// #2518
errout.str("");