Browse Source

cppparser: Fix crash redefining struct as typedef

This would crash on the following code:

    struct aaa;
    typedef struct {} aaa;
rdb 1 year ago
parent
commit
78f1a5b15a
2 changed files with 5 additions and 3 deletions
  1. 1 1
      dtool/src/cppparser/cppExtensionType.cxx
  2. 4 2
      dtool/src/cppparser/cppScope.cxx

+ 1 - 1
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;
 }
 
 /**

+ 4 - 2
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 {