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/gui/itemmodels | |
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/gui/itemmodels')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 23 |
1 files changed, 11 insertions, 12 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); |