fix #7505 (crash on invalid code)

This commit is contained in:
Matthias Krüger 2016-05-25 13:14:34 +02:00
parent 728d4242dc
commit 0556edd151
2 changed files with 6 additions and 1 deletions

View File

@ -3258,7 +3258,7 @@ const Token * Scope::addEnum(const Token * tok, bool isCpp)
if (tok2 == end) { if (tok2 == end) {
tok2 = tok2->next(); tok2 = tok2->next();
if (tok2->str() != ";") if (tok2 && tok2->str() != ";")
tok2 = nullptr; tok2 = nullptr;
} else } else
tok2 = nullptr; tok2 = nullptr;

View File

@ -231,6 +231,7 @@ private:
TEST_CASE(garbageCode180); TEST_CASE(garbageCode180);
TEST_CASE(garbageCode181); TEST_CASE(garbageCode181);
TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1515,6 +1516,10 @@ private:
void garbageCode182() { void garbageCode182() {
ASSERT_THROW(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError); ASSERT_THROW(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError);
} }
// #7505 - segfault
void garbageCode183() {
ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError);
}
}; };