From 78f1a5b15a940350b3061eb86fbd3ea3de07f8c9 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 28 Mar 2024 11:08:38 +0100 Subject: [PATCH] cppparser: Fix crash redefining struct as typedef This would crash on the following code: struct aaa; typedef struct {} aaa; --- dtool/src/cppparser/cppExtensionType.cxx | 2 +- dtool/src/cppparser/cppScope.cxx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dtool/src/cppparser/cppExtensionType.cxx b/dtool/src/cppparser/cppExtensionType.cxx index bf0b963378..f82735274d 100644 --- a/dtool/src/cppparser/cppExtensionType.cxx +++ b/dtool/src/cppparser/cppExtensionType.cxx @@ -211,7 +211,7 @@ is_equivalent(const CPPType &other) const { // We consider two different extension types to be equivalent if they have // the same name. - return *_ident == *ot->_ident; + return _ident != nullptr && ot->_ident != nullptr && *_ident == *ot->_ident; } /** diff --git a/dtool/src/cppparser/cppScope.cxx b/dtool/src/cppparser/cppScope.cxx index af6404e4dd..d091cae756 100644 --- a/dtool/src/cppparser/cppScope.cxx +++ b/dtool/src/cppparser/cppScope.cxx @@ -164,8 +164,10 @@ define_typedef_type(CPPTypedefType *type, CPPPreprocessor *error_sink) { errstr << " has conflicting declaration as "; other_type->output(errstr, 0, nullptr, true); error_sink->error(errstr.str(), type->_ident->_loc); - error_sink->error("previous definition is here", - other_td->_ident->_loc); + if (other_td != nullptr && other_td->_ident != nullptr) { + error_sink->error("previous definition is here", + other_td->_ident->_loc); + } } } } else {