From 3f0b32f1ee7d8ce6dc67cd6fb8a036d678421e54 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 17 Feb 2018 14:16:35 -0500 Subject: [PATCH] qdict: Make conversion from QObject * accept null qobject_to_qdict() crashes on null, which is a trap for the unwary. Return null instead, and simplify a few callers. Backports commit 89cad9f3ec6b30d7550fb5704475fc9c3393a066 from qemu --- qemu/qobject/qdict.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu/qobject/qdict.c b/qemu/qobject/qdict.c index 873277f3..d650a16b 100644 --- a/qemu/qobject/qdict.c +++ b/qemu/qobject/qdict.c @@ -46,9 +46,9 @@ QDict *qdict_new(void) */ QDict *qobject_to_qdict(const QObject *obj) { - if (qobject_type(obj) != QTYPE_QDICT) + if (!obj || qobject_type(obj) != QTYPE_QDICT) { return NULL; - + } return container_of(obj, QDict, base); } @@ -269,7 +269,7 @@ QList *qdict_get_qlist(const QDict *qdict, const char *key) */ QDict *qdict_get_qdict(const QDict *qdict, const char *key) { - return qobject_to_qdict(qdict_get_obj(qdict, key, QTYPE_QDICT)); + return qobject_to_qdict(qdict_get(qdict, key)); } /**