From 9c964cdd978c6f5c113df9cc0ebd857a9ee4fd2f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 17 Aug 2019 15:53:51 +0800 Subject: [PATCH] Fix using out-of-bounds of indexes --- src/gui/torrentcontentfiltermodel.cpp | 4 ++-- src/gui/torrentcontentmodel.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/torrentcontentfiltermodel.cpp b/src/gui/torrentcontentfiltermodel.cpp index abb22ed4b..8f91b0711 100644 --- a/src/gui/torrentcontentfiltermodel.cpp +++ b/src/gui/torrentcontentfiltermodel.cpp @@ -107,7 +107,7 @@ void TorrentContentFilterModel::selectAll() for (int i = 0; i < rowCount(); ++i) setData(index(i, 0), Qt::Checked, Qt::CheckStateRole); - emit dataChanged(index(0,0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } void TorrentContentFilterModel::selectNone() @@ -115,7 +115,7 @@ void TorrentContentFilterModel::selectNone() for (int i = 0; i < rowCount(); ++i) setData(index(i, 0), Qt::Unchecked, Qt::CheckStateRole); - emit dataChanged(index(0,0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } bool TorrentContentFilterModel::hasFiltered(const QModelIndex &folder) const diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index e2ff20a04..9b4eff3dc 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -228,7 +228,7 @@ void TorrentContentModel::updateFilesProgress(const QVector &fp) // Update folders progress in the tree m_rootItem->recalculateProgress(); m_rootItem->recalculateAvailability(); - emit dataChanged(index(0, 0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } void TorrentContentModel::updateFilesPriorities(const QVector &fprio) @@ -241,7 +241,7 @@ void TorrentContentModel::updateFilesPriorities(const QVectorsetPriority(static_cast(fprio[i])); - emit dataChanged(index(0, 0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } void TorrentContentModel::updateFilesAvailability(const QVector &fa) @@ -255,7 +255,7 @@ void TorrentContentModel::updateFilesAvailability(const QVector &fa) m_filesIndex[i]->setAvailability(fa[i]); // Update folders progress in the tree m_rootItem->recalculateProgress(); - emit dataChanged(index(0, 0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } QVector TorrentContentModel::getFilePriorities() const @@ -302,7 +302,7 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu // Update folders progress in the tree m_rootItem->recalculateProgress(); m_rootItem->recalculateAvailability(); - emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1)); + emit dataChanged(this->index(0, 0), this->index((rowCount() - 1), (columnCount() - 1))); emit filteredFilesChanged(); } return true; @@ -502,12 +502,12 @@ void TorrentContentModel::selectAll() if (child->priority() == BitTorrent::DownloadPriority::Ignored) child->setPriority(BitTorrent::DownloadPriority::Normal); } - emit dataChanged(index(0, 0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); } void TorrentContentModel::selectNone() { for (int i = 0; i < m_rootItem->childCount(); ++i) m_rootItem->child(i)->setPriority(BitTorrent::DownloadPriority::Ignored); - emit dataChanged(index(0, 0), index(rowCount(), columnCount())); + emit dataChanged(index(0, 0), index((rowCount() - 1), (columnCount() - 1))); }