diff options
author | Maks Naumov <maksqwe1@ukr.net> | 2015-01-24 21:26:06 +0200 |
---|---|---|
committer | Maks Naumov <maksqwe1@ukr.net> | 2015-02-06 09:43:38 +0000 |
commit | b444769840b2497f1295bca0694fe59aa78bb551 (patch) | |
tree | c4813f4e963a254a094a7a8c85348128f0832557 /src | |
parent | b3fc5e1ea3eb4fe838ac716aaca4efaa5de5a814 (diff) |
Don't crash with invalid QModelIndex or when QTreeWidgetItem is NULL in mimeData()
Change-Id: I0a9abaa05cf136eadf222d3e7d102930719b84ff
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 23 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget.cpp | 12 |
2 files changed, 22 insertions, 13 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index 44ee710268..eae2b419e3 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -2942,9 +2942,13 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const itemsSet.reserve(indexes.count()); stack.reserve(indexes.count()); for (int i = 0; i < indexes.count(); ++i) { - QStandardItem *item = itemFromIndex(indexes.at(i)); - itemsSet << item; - stack.push(item); + if (QStandardItem *item = itemFromIndex(indexes.at(i))) { + itemsSet << item; + stack.push(item); + } else { + qWarning() << "QStandardItemModel::mimeData: No item associated with invalid index"; + return 0; + } } //remove duplicates childrens @@ -2978,16 +2982,11 @@ QMimeData *QStandardItemModel::mimeData(const QModelIndexList &indexes) const //stream everything recursively while (!stack.isEmpty()) { QStandardItem *item = stack.pop(); - if(itemsSet.contains(item)) { //if the item is selection 'top-level', strem its position + if (itemsSet.contains(item)) //if the item is selection 'top-level', stream its position stream << item->row() << item->column(); - } - if(item) { - stream << *item << item->columnCount() << item->d_ptr->children.count(); - stack += item->d_ptr->children; - } else { - QStandardItem dummy; - stream << dummy << 0 << 0; - } + + stream << *item << item->columnCount() << item->d_ptr->children.count(); + stack += item->d_ptr->children; } data->setData(format, encoded); diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 7378b9979a..769a5b97b9 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -3273,8 +3273,18 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const QList<QModelIndex> indexes; for (int i = 0; i < items.count(); ++i) { QTreeWidgetItem *item = items.at(i); + if (!item) { + qWarning() << "QTreeWidget::mimeData: Null-item passed"; + return 0; + } + for (int c = 0; c < item->values.count(); ++c) { - indexes << indexFromItem(item, c); + const QModelIndex index = indexFromItem(item, c); + if (!index.isValid()) { + qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item; + return 0; + } + indexes << index; } } return d->model->QAbstractItemModel::mimeData(indexes); |