Permalink
Browse files

Fixed ticket #3571 (segmentation fault of cppcheck while scanning gcc…

…-testsuite).
  • Loading branch information...
1 parent f8578a3 commit 66e1761ffea0c9303dd900f7b6e6efde27c8a40e Edoardo Prezioso committed Jan 31, 2012
Showing with 16 additions and 5 deletions.
  1. +14 −5 lib/tokenize.cpp
  2. +2 −0 test/testtokenize.cpp
View
@@ -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
@@ -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() {

0 comments on commit 66e1761

Please sign in to comment.