[gjs/11-handle-0-valued-gtype-gracefully] js: convert GType of 0 to null



commit 63159f9a00e316297a255a17f04caa7996a11aad
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Nov 3 16:16:00 2017 +0100

    js: convert GType of 0 to null
    
    Zero is a valid return value for GLib's type_from_name() in case the
    type in question is not registered. It needs to be handled gracefully.
    
      $ ./gjs-console -c 'print (imports.gi.GObject.type_from_name ("Nonexistent"))'
    
      (lt-gjs-console:18975): GLib-GObject-CRITICAL **: g_type_get_qdata: assertion 'node != NULL' failed
    
      (lt-gjs-console:18975): GLib-GObject-CRITICAL **: g_type_set_qdata: assertion 'node != NULL' failed
      [object GType prototype]
    
      (lt-gjs-console:18975): GLib-GObject-CRITICAL **: g_type_get_qdata: assertion 'node != NULL' failed
      Segmentation fault (core dumped)
      $

 gi/gtype.cpp | 3 +++
 1 file changed, 3 insertions(+)
---
diff --git a/gi/gtype.cpp b/gi/gtype.cpp
index 411f092..32aaf92 100644
--- a/gi/gtype.cpp
+++ b/gi/gtype.cpp
@@ -158,6 +158,9 @@ gjs_gtype_create_gtype_wrapper (JSContext *context,
 {
     JSAutoRequest ar(context);
 
+    if (gtype == 0)
+        return nullptr;
+
     auto heap_wrapper =
         static_cast<JS::Heap<JSObject *> *>(g_type_get_qdata(gtype, gjs_get_gtype_wrapper_quark()));
     if (heap_wrapper != nullptr)


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