aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorDaniel Vrátil <daniel.vratil@kdab.com>2018-03-20 18:14:20 +0100
committerDaniel Vrátil <daniel.vratil@kdab.com>2018-03-20 22:36:00 +0000
commitcc62a35bbebc9d069c9dbaeb703dfd6afea548e3 (patch)
tree4bbb3c129fc617b3d01c8e4e17edfaf6aa8ad8f3 /src/qml
parent2b0e0bee0c6153a8912778de5ff1cabd728d98d8 (diff)
Fix QQmlListModel crash when appending an empty array in debug mode
Calling QQmlListModel::append() with an empty JS array triggers an assert in QAbstractItemModel::beginInsertRows() because it's called with negative "last" parameter. Change-Id: I202da260d79f2e6677c663c5785ff754c715fef8 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/types/qqmllistmodel.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index d4fc02cd3e..c4e33d572d 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -2351,21 +2351,22 @@ void QQmlListModel::append(QQmlV4Function *args)
QV4::ScopedObject argObject(scope);
int objectArrayLength = objectArray->getLength();
+ if (objectArrayLength > 0) {
+ int index = count();
+ emitItemsAboutToBeInserted(index, objectArrayLength);
- int index = count();
- emitItemsAboutToBeInserted(index, objectArrayLength);
+ for (int i=0 ; i < objectArrayLength ; ++i) {
+ argObject = objectArray->getIndexed(i);
- for (int i=0 ; i < objectArrayLength ; ++i) {
- argObject = objectArray->getIndexed(i);
-
- if (m_dynamicRoles) {
- m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this));
- } else {
- m_listModel->append(argObject);
+ if (m_dynamicRoles) {
+ m_modelObjects.append(DynamicRoleModelNode::create(scope.engine->variantMapFromJS(argObject), this));
+ } else {
+ m_listModel->append(argObject);
+ }
}
- }
- emitItemsInserted();
+ emitItemsInserted();
+ }
} else if (argObject) {
int index;