fix daca crashes in Type::findDependency() (#3101)

This commit is contained in:
IOBYTE 2021-01-31 04:07:03 -05:00 committed by GitHub
parent b2fbab18fd
commit 5810171336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -3139,7 +3139,7 @@ bool Type::findDependency(const Type* ancestor) const
if (this==ancestor)
return true;
for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.begin(); parent!=derivedFrom.end(); ++parent) {
if (parent->type && parent->type->findDependency(ancestor))
if (parent->type && (parent->type == this || parent->type->findDependency(ancestor)))
return true;
}
return false;

View File

@ -344,6 +344,7 @@ private:
TEST_CASE(symboldatabase89); // valuetype name
TEST_CASE(symboldatabase90);
TEST_CASE(symboldatabase91);
TEST_CASE(symboldatabase92); // daca crash
TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4680,6 +4681,14 @@ private:
ASSERT(functok->function()->name() == "foo");
}
void symboldatabase92() { // daca crash
GET_SYMBOL_DB("template <size_t, typename...> struct a;\n"
"template <size_t b, typename c, typename... d>\n"
"struct a<b, c, d...> : a<1, d...> {};\n"
"template <typename... e> struct f : a<0, e...> {};");
ASSERT_EQUALS("", errout.str());
}
void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);