From: Chris Adams Date: Wed, 3 Aug 2011 05:45:47 +0000 (+1000) Subject: Fix crash in QDeclarativeProperty X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=02a19405aab1df31a40896de3d928d8878402052;p=konrad%2Fqtdeclarative.git Fix crash in QDeclarativeProperty 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 Reviewed-by: Simon Hausmann Reviewed-by: Aaron Kennedy --- diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 98c7582..3406109 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -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 index 0000000..f58967c --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeA.qml @@ -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 index 0000000..4b36728 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeproperty/data/NoContextTypeB.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +QtObject { + property NoContextTypeA myTypeA +}