Fix crash in QDeclarativeProperty
authorChris Adams <christopher.adams@nokia.com>
Wed, 3 Aug 2011 05:45:47 +0000 (15:45 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 4 Aug 2011 00:37:58 +0000 (02:37 +0200)
This commit ensures that we don't attempt to dereference a null
pointer in QDeclarativeProperty.  It also fixes a unit test failure
by adding appropriate test files.
Related to commit 9f9b23fd7943a3d125cb1cc9f333ce430b2706ea

Task-number: QTBUG-14697
Change-Id: Ic60521e46401835029e293349a00610342d0d58f
Reviewed-on: http://codereview.qt.nokia.com/2538
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>

src/declarative/qml/qdeclarativeproperty.cpp
tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeA.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeB.qml [new file with mode: 0644]

index 98c7582..3406109 100644 (file)
@@ -399,7 +399,7 @@ const char *QDeclarativeProperty::propertyTypeName() const
         return 0;
     if (d->isValueType()) {
 
-        QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(d->engine);
+        QDeclarativeEnginePrivate *ep = d->engine?QDeclarativeEnginePrivate::get(d->engine):0;
         QDeclarativeValueType *valueType = 0;
         if (ep) valueType = ep->valueTypes[d->core.propType];
         else valueType = QDeclarativeValueTypeFactory::valueType(d->core.propType);
@@ -987,7 +987,7 @@ QVariant QDeclarativePropertyPrivate::readValueProperty()
 {
     if (isValueType()) {
 
-        QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+        QDeclarativeEnginePrivate *ep = engine?QDeclarativeEnginePrivate::get(engine):0;
         QDeclarativeValueType *valueType = 0;
         if (ep) valueType = ep->valueTypes[core.propType];
         else valueType = QDeclarativeValueTypeFactory::valueType(core.propType);
@@ -1072,7 +1072,7 @@ bool QDeclarativePropertyPrivate::writeValueProperty(const QVariant &value, Writ
 
     bool rv = false;
     if (isValueType()) {
-        QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+        QDeclarativeEnginePrivate *ep = engine?QDeclarativeEnginePrivate::get(engine):0;
 
         QDeclarativeValueType *writeBack = 0;
         if (ep) {
diff --git a/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeA.qml b/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeA.qml
new file mode 100644 (file)
index 0000000..f58967c
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+QtObject {
+    property string someString
+}
diff --git a/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeB.qml b/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeB.qml
new file mode 100644 (file)
index 0000000..4b36728
--- /dev/null
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+QtObject {
+    property NoContextTypeA myTypeA
+}