qlist: Make conversion from QObject * accept null

qobject_to_qlist() crashes on null, which is a trap for the unwary.
Return null instead.

Backports commit 2d6421a90047a83f6722832405fe09571040ea5b from qemu
This commit is contained in:
Markus Armbruster 2018-02-17 14:21:26 -05:00 committed by Lioncash
parent 218e3ab5d5
commit d25b8420d0
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -142,10 +142,9 @@ size_t qlist_size(const QList *qlist)
*/
QList *qobject_to_qlist(const QObject *obj)
{
if (qobject_type(obj) != QTYPE_QLIST) {
if (!obj || qobject_type(obj) != QTYPE_QLIST) {
return NULL;
}
return container_of(obj, QList, base);
}