Fixed ticket #3571 (segmentation fault of cppcheck while scanning gcc-testsuite).

This commit is contained in:
Edoardo Prezioso 2012-01-31 18:41:57 +01:00
parent f8578a380a
commit 66e1761ffe
2 changed files with 16 additions and 5 deletions

View File

@ -5166,19 +5166,28 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar)
tok2 = tok2->tokAt(2);
if (tok2 && tok2->previous()->str() == "::")
continue;
size_t indentlevel = 1;
unsigned int indentlevel = 0;
unsigned int parens = 0;
for (Token *tok3 = tok2; tok3; tok3 = tok3->next()) {
++typelen;
if (tok3->str() == "<") {
if (tok3->str() == "<" && !parens) {
++indentlevel;
} else if (tok3->str() == ">") {
--indentlevel;
if (indentlevel == 0) {
} else if (tok3->str() == ">" && !parens) {
if (!indentlevel) {
tok2 = tok3->next();
break;
}
--indentlevel;
} else if (tok3->str() == "(") {
++parens;
} else if (tok3->str() == ")") {
if (!parens) {
tok2 = NULL;
break;
}
--parens;
} else if (tok3->str() == ";") {
break;
}

View File

@ -4426,6 +4426,8 @@ private:
const char code1[] = "b<(1<<24),10,24> u, v;";
const char res1[] = "b < ( 1 << 24 ) , 10 , 24 > u ; b < ( 1 << 24 ) , 10 , 24 > v ;";
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
// ticket #3571 (segmentation fault)
tokenizeAndStringify("template <int i = (3>4) > class X4 {};");
}
void vardecl_union() {