From f9f1043e8a7706cbf6011ff4a42922b976b7a7fd Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 9 Sep 2020 10:37:19 +0200 Subject: QVariant: guard usage of fromType.metaObject() This patch amends 19874d6a63. That patch caused a crash to occur when running the auto test tst_QQuickApplicationWindow::attachedProperties(). The crash can be traced back to QMetaType trying to access fromType.metaObject(), which is null. This patch will add a guard to ensure that we don't try to call a function on an object that is null. Fixes: QTBUG-86517 Change-Id: Idafd154a7b6a43e16126038fc5f9b30d7871f0d0 Reviewed-by: Mitch Curtis Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/kernel/qmetatype.cpp') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 553929955d..7b78b96d09 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -2049,7 +2049,7 @@ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType, if (fromObject && fromObject->metaObject()->inherits(toType.metaObject())) { *static_cast(to) = toType.metaObject()->cast(fromObject); return true; - } else if (!fromObject) { + } else if (!fromObject && fromType.metaObject()) { // if fromObject is null, use static fromType to check if conversion works *static_cast(to) = nullptr; return fromType.metaObject()->inherits(toType.metaObject()); -- cgit v1.2.3