add null check for qmlRegisterSingletonType()
authorTasuku Suzuki <tasuku@ptp.co.jp>
Tue, 7 Jul 2015 14:08:30 +0000 (23:08 +0900)
committerTasuku Suzuki (PTP) <tasuku@ptp.co.jp>
Fri, 24 Jul 2015 02:55:54 +0000 (02:55 +0000)
When the callback passed to the function returns nullptr,
QQmlData::ensurePropertyCache(e, o) crashes.

Change-Id: I11efd7e9d6c5f18611e796d896384dd14a280303
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
src/qml/qml/qqmlmetatype.cpp

index 41d44a8..cb8c2bd 100644 (file)
@@ -225,6 +225,9 @@ void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e)
         v4->pushGlobalContext();
         QObject *o = qobjectCallback(e, e);
         setQObjectApi(e, o);
+        if (!o) {
+            qFatal("qmlRegisterSingletonType(): \"%s\" is not available because the callback function returns a null pointer.", qPrintable(typeName));
+        }
         // if this object can use a property cache, create it now
         QQmlData::ensurePropertyCache(e, o);
         v4->popContext();