From b2e79e0b5c26e70ad586cb965808059330cc0893 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 4 Oct 2010 13:39:47 +1000 Subject: Prevent crash in XmlListModel when appending an empty role. --- src/declarative/util/qdeclarativexmllistmodel.cpp | 2 +- .../declarative/qdeclarativexmllistmodel/data/roleCrash.qml | 7 +++++++ .../qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativexmllistmodel/data/roleCrash.qml diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 24edc89..ce5b483 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -476,7 +476,7 @@ public: void QDeclarativeXmlListModelPrivate::append_role(QDeclarativeListProperty *list, QDeclarativeXmlListModelRole *role) { QDeclarativeXmlListModel *_this = qobject_cast(list->object); - if (_this) { + if (_this && role) { int i = _this->d_func()->roleObjects.count(); _this->d_func()->roleObjects.append(role); if (_this->d_func()->roleNames.contains(role->name())) { diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/data/roleCrash.qml b/tests/auto/declarative/qdeclarativexmllistmodel/data/roleCrash.qml new file mode 100644 index 0000000..492dad9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativexmllistmodel/data/roleCrash.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +XmlListModel { + id: model + XmlRole {} + Component.onCompleted: model.roles = 0 +} diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index bd19bd3..a14f942 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -96,6 +96,8 @@ private slots: void threading_data(); void propertyChanges(); + void roleCrash(); + private: QString makeItemXmlAndData(const QString &data, QDeclarativeXmlModelData *modelData = 0) const { @@ -825,6 +827,15 @@ void tst_qdeclarativexmllistmodel::propertyChanges() delete model; } +void tst_qdeclarativexmllistmodel::roleCrash() +{ + // don't crash + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleCrash.qml")); + QDeclarativeXmlListModel *model = qobject_cast(component.create()); + QVERIFY(model != 0); + delete model; +} + QTEST_MAIN(tst_qdeclarativexmllistmodel) #include "tst_qdeclarativexmllistmodel.moc" -- cgit v0.12