fix #3005 (segmentation fault of cppcheck ( enum : x ))

This commit is contained in:
Robert Reif 2011-08-15 07:07:12 -04:00
parent 5364b4f7fb
commit 4168d79b09
2 changed files with 18 additions and 4 deletions

View File

@ -8294,19 +8294,25 @@ void Tokenizer::simplifyEnum()
if (!tok->next())
{
syntaxError(tok);
return;
return; // can't recover
}
typeTokenStart = tok->next();
tok = tok->next();
typeTokenEnd = typeTokenStart;
while (typeTokenEnd->next()->str() == "::" ||
Token::Match(typeTokenEnd->next(), "%type%"))
while (typeTokenEnd->next() && (typeTokenEnd->next()->str() == "::" ||
Token::Match(typeTokenEnd->next(), "%type%")))
{
typeTokenEnd = typeTokenEnd->next();
tok = tok->next();
}
if (!tok->next())
{
syntaxError(tok);
return; // can't recover
}
}
// check for forward declaration

View File

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