cppparser: Fix crash redefining struct as typedef

This would crash on the following code:

    struct aaa;
    typedef struct {} aaa;
This commit is contained in:
rdb 2024-03-28 11:08:38 +01:00
parent 014fd97fef
commit 78f1a5b15a
2 changed files with 5 additions and 3 deletions

View File

@ -211,7 +211,7 @@ is_equivalent(const CPPType &other) const {
// We consider two different extension types to be equivalent if they have // We consider two different extension types to be equivalent if they have
// the same name. // the same name.
return *_ident == *ot->_ident; return _ident != nullptr && ot->_ident != nullptr && *_ident == *ot->_ident;
} }
/** /**

View File

@ -164,8 +164,10 @@ define_typedef_type(CPPTypedefType *type, CPPPreprocessor *error_sink) {
errstr << " has conflicting declaration as "; errstr << " has conflicting declaration as ";
other_type->output(errstr, 0, nullptr, true); other_type->output(errstr, 0, nullptr, true);
error_sink->error(errstr.str(), type->_ident->_loc); error_sink->error(errstr.str(), type->_ident->_loc);
error_sink->error("previous definition is here", if (other_td != nullptr && other_td->_ident != nullptr) {
other_td->_ident->_loc); error_sink->error("previous definition is here",
other_td->_ident->_loc);
}
} }
} }
} else { } else {