fix #2834 (crash of cppcheck (std::vector<int>::iterator))

This commit is contained in:
Robert Reif 2011-06-12 08:24:49 -04:00
parent 5e3263235b
commit d1b260699a
2 changed files with 14 additions and 3 deletions

View File

@ -5931,7 +5931,7 @@ void Tokenizer::simplifyVarDecl()
} }
} }
if (!tok2) if (!tok2) // syntax error
break; break;
if (Token::Match(tok2, ":: %type%")) if (Token::Match(tok2, ":: %type%"))
@ -5940,6 +5940,9 @@ void Tokenizer::simplifyVarDecl()
tok2 = tok2->tokAt(2); tok2 = tok2->tokAt(2);
} }
if (!tok2) // syntax error
break;
if (tok2->str() == "*") if (tok2->str() == "*")
{ {
tok2 = tok2->next(); tok2 = tok2->next();

View File

@ -352,7 +352,8 @@ private:
TEST_CASE(removeUnnecessaryQualification2); TEST_CASE(removeUnnecessaryQualification2);
TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyIfNotNull);
TEST_CASE(simplifyVarDecl); // ticket # 2682 segmentation fault TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault
TEST_CASE(simplifyVarDecl2); // ticket # 2834 segmentation fault
} }
std::string tok(const char code[], bool simplify = true) std::string tok(const char code[], bool simplify = true)
@ -6986,12 +6987,19 @@ private:
} }
} }
void simplifyVarDecl() // ticket # 2682 segmentation fault void simplifyVarDecl1() // ticket # 2682 segmentation fault
{ {
const char code[] = "x a[0] ="; const char code[] = "x a[0] =";
tok(code, false); tok(code, false);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyVarDecl2() // ticket # 2834 segmentation fault
{
const char code[] = "std::vector<int>::iterator";
tok(code, false);
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestSimplifyTokens) REGISTER_TEST(TestSimplifyTokens)