Skip to contentSkip to conversation

QOM: Fail casts for unknown types

PATCH Applied Alexander Graf 4 participants 4 messages Apr 30, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 QOM: Fail casts for unknown types

When we try to cast an object to an unknown type, fail the cast. Today we would simply run into an assert().

This fixes a bug on qemu-system-s390x for me that gets triggered by the audio code looking for PCI and ISA buses.

---
 qom/object.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
qom/object.c +5 -0
index dd53d24..75e6aac 100644
@@ -453,6 +453,11 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
     TypeImpl *type = class->type;
     ObjectClass *ret = NULL;
 
+    if (!target_type) {
+        /* target class type unknown, so fail the cast */
+        return NULL;
+    }
+
     if (type->class->interfaces &&
             type_is_ancestor(target_type, type_interface)) {
         int found = 0;
Signature · 1 line
1.6.0.2
Reviewed-by on v1 1/1
#1 lore raw

Il 30/04/2013 15:02, Alexander Graf ha scritto:

Quoted 7 lines

When we try to cast an object to an unknown type, fail the cast. Today we would simply run into an assert().

This fixes a bug on qemu-system-s390x for me that gets triggered by the audio code looking for PCI and ISA buses.

Seems a better solution than guarding the object_resolve_path_type with an if.

Paolo

Quoted 21 lines
---
 qom/object.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
qom/object.c +5 -0
index dd53d24..75e6aac 100644
@@ -453,6 +453,11 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
     TypeImpl *type = class->type;
     ObjectClass *ret = NULL;
 
+    if (!target_type) {
+        /* target class type unknown, so fail the cast */
+        return NULL;
+    }
+
     if (type->class->interfaces &&
             type_is_ancestor(target_type, type_interface)) {
         int found = 0;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Alexander Graf

Am 30.04.2013 15:02, schrieb Alexander Graf:

Quoted 7 lines

When we try to cast an object to an unknown type, fail the cast. Today we would simply run into an assert().

This fixes a bug on qemu-system-s390x for me that gets triggered by the audio code looking for PCI and ISA buses.

but "qom: ..." please, for proportional (Web) fonts. :)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg