fix #2978 (segmentation fault of cppcheck ( enum E {} e enum ))

This commit is contained in:
Robert Reif 2011-08-07 16:48:47 -04:00
parent cfcfa3f000
commit 829611b129
2 changed files with 9 additions and 1 deletions

View File

@ -8531,7 +8531,7 @@ void Tokenizer::simplifyEnum()
simplify = true;
hasClass = true;
}
else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next()->str() == enumType->str())))
else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str())))
{
if (Token::simpleMatch(tok2->previous(), "::"))
{

View File

@ -313,6 +313,7 @@ private:
TEST_CASE(enum23); // ticket #2804
TEST_CASE(enum24); // ticket #2828
TEST_CASE(enum25); // ticket #2966
TEST_CASE(enum26); // ticket #2975 (segmentation fault)
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -6657,6 +6658,13 @@ private:
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
void enum26() // ticket #2978 (segmentation fault)
{
const char code[] = "enum E {} e enum\n";
tok(code, false);
ASSERT_EQUALS("", errout.str());
}
void removestd()
{
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));