qom: allow object_get_canonical_path_component without parent
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 30 Apr 2018 09:44:17 +0000 (11:44 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 8 May 2018 22:13:37 +0000 (00:13 +0200)
Just return NULL; any callers that cause a change in behavior
would have caused an assertion failure before, so this is safe.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qom/object.h
qom/object.c

index 96ce81bc5e677a3b78ec7c498b22a5c132c3c259..a0c78c76f7cd196200f2367927ac018a6fe11abd 100644 (file)
@@ -1302,6 +1302,7 @@ Object *object_get_internal_root(void);
  *
  * Returns: The final component in the object's canonical path.  The canonical
  * path is the path within the composition tree starting from the root.
+ * %NULL if the object doesn't have a parent (and thus a canonical path).
  */
 gchar *object_get_canonical_path_component(Object *obj);
 
index 76a89af99bf1e8f97718b6e6a146212ad2ac2fad..0fc972030eed3e91d34153673553d3b2b7eb5a20 100644 (file)
@@ -1644,8 +1644,9 @@ gchar *object_get_canonical_path_component(Object *obj)
     ObjectProperty *prop = NULL;
     GHashTableIter iter;
 
-    g_assert(obj);
-    g_assert(obj->parent != NULL);
+    if (obj->parent == NULL) {
+        return NULL;
+    }
 
     g_hash_table_iter_init(&iter, obj->parent->properties);
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) {