[glibmm] Type registration: Ignore NULL GTypes, preventing crashes.



commit 9fe5b9697f3520f1581d21cd05b5ad03b55af678
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu May 14 22:43:08 2009 +0200

    Type registration: Ignore NULL GTypes, preventing crashes.
    
    * glib/glibmm/wrap.cc: wrap_register(): Silently ignore NULL GTypes.
    * glib/glibmm/class.cc: register_derived_type(): Silently ignore NULL
    GTypes. Use g_strconcat() instead of ustring+= to maybe make it more
    efficient. This helps gstreamermm, which may try to use type names of
    plugins that are not actually available on the system.
---
 ChangeLog            |   10 ++++++++++
 glib/glibmm/class.cc |   17 ++++++++++++++---
 glib/glibmm/wrap.cc  |    6 ++++++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4269a01..3fbb01d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-05-14  Murray Cumming  <murrayc murrayc com>
+
+	Type registration: Ignore NULL GTypes, preventing crashes.
+
+	* glib/glibmm/wrap.cc: wrap_register(): Silently ignore NULL GTypes.
+	* glib/glibmm/class.cc: register_derived_type(): Silently ignore NULL 
+	GTypes. Use g_strconcat() instead of ustring+= to maybe make it more 
+	efficient. This helps gstreamermm, which may try to use type names of 
+	plugins that are not actually available on the system.
+
 2009-05-06  Chris Vine  <chris cvine freeserve co uk>
 
 	* glib/glibmm/ustring.h (ustring_Iterator<>): Turn the relational
diff --git a/glib/glibmm/class.cc b/glib/glibmm/class.cc
index cb3c875..3127c69 100644
--- a/glib/glibmm/class.cc
+++ b/glib/glibmm/class.cc
@@ -32,6 +32,12 @@ void Class::register_derived_type(GType base_type)
   if(gtype_)
     return; // already initialized
 
+  //0 is not a valid GType.
+  //It would lead to a crash later.
+  //We allow this, failing silently, to make life easier for gstreamermm.
+  if(base_type == 0)
+    return; // already initialized
+
   GTypeQuery base_query = { 0, 0, 0, 0, };
   g_type_query(base_type, &base_query);
 
@@ -49,10 +55,15 @@ void Class::register_derived_type(GType base_type)
     0, // value_table
   };
 
-  Glib::ustring derived_name = "gtkmm__";
-  derived_name += base_query.type_name;
+  if(!(base_query.type_name))
+  {
+    g_critical("Class::register_derived_type(): base_query.type_name is NULL.");
+    return;
+  }
 
-  gtype_ = g_type_register_static(base_type, derived_name.c_str(), &derived_info, GTypeFlags(0));
+  gchar* derived_name = g_strconcat("gtkmm__", base_query.type_name, NULL);
+  gtype_ = g_type_register_static(base_type, derived_name, &derived_info, GTypeFlags(0));
+  g_free(derived_name);
 }
 
 GType Class::clone_custom_type(const char* custom_type_name) const
diff --git a/glib/glibmm/wrap.cc b/glib/glibmm/wrap.cc
index c283b3a..4541b62 100644
--- a/glib/glibmm/wrap.cc
+++ b/glib/glibmm/wrap.cc
@@ -82,6 +82,12 @@ void wrap_register_cleanup()
 //
 void wrap_register(GType type, WrapNewFunction func)
 {
+  //0 is not a valid GType.
+  //It would lead to a critical warning in g_type_set_qdata().
+  //We allow this, failing silently, to make life easier for gstreamermm.
+  if(type == 0)
+    return;
+
   const guint idx = wrap_func_table->size();
   wrap_func_table->push_back(func);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]