Skip to content

Commit

Permalink
Fixed ticket #3571 (segmentation fault of cppcheck while scanning gcc…
Browse files Browse the repository at this point in the history
…-testsuite).
  • Loading branch information
Edoardo Prezioso committed Jan 31, 2012
1 parent f8578a3 commit 66e1761
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4426,6 +4426,8 @@ class TestTokenizer : public TestFixture {
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() {
Expand Down

0 comments on commit 66e1761

Please sign in to comment.