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
This commit is contained in:
Markus Armbruster 2018-02-17 14:16:35 -05:00 committed by Lioncash
parent 41ca5bddb8
commit 3f0b32f1ee
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -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));
}
/**