#6742 segmentation fault (invalid code) in SymbolDatabase::SymbolDatabase. Fix in Type::initBaseInfo()

This commit is contained in:
Alexander Mai 2015-06-02 20:15:21 +02:00
parent f348c8eebe
commit 454d4573b4
2 changed files with 9 additions and 1 deletions

View File

@ -1962,7 +1962,8 @@ const Token *Type::initBaseInfo(const Token *tok, const Token *tok1)
} }
base.nameTok = tok2; base.nameTok = tok2;
if (!tok2)
return nullptr;
// handle global namespace // handle global namespace
if (tok2->str() == "::") { if (tok2->str() == "::") {
tok2 = tok2->next(); tok2 = tok2->next();
@ -1972,6 +1973,8 @@ const Token *Type::initBaseInfo(const Token *tok, const Token *tok1)
while (Token::Match(tok2, "%name% ::")) { while (Token::Match(tok2, "%name% ::")) {
tok2 = tok2->tokAt(2); tok2 = tok2->tokAt(2);
} }
if (!tok2)
return nullptr;
base.name = tok2->str(); base.name = tok2->str();

View File

@ -104,6 +104,7 @@ private:
TEST_CASE(garbageCode63); TEST_CASE(garbageCode63);
TEST_CASE(garbageCode64); TEST_CASE(garbageCode64);
TEST_CASE(garbageCode65); TEST_CASE(garbageCode65);
TEST_CASE(garbageCode66);
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
@ -585,6 +586,10 @@ private:
ASSERT_THROW(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref"), InternalError); ASSERT_THROW(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref"), InternalError);
} }
void garbageCode66() { // #6742
ASSERT_THROW(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), InternalError);
}
void garbageValueFlow() { void garbageValueFlow() {
// #6089 // #6089