From a94091714419f7d10356ab69c380644a778923f5 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 8 Apr 2012 11:17:32 +0300 Subject: [PATCH] Add more vector length checks --- src/properties/propertieswidget.cpp | 2 +- src/torrentadditiondlg.cpp | 8 ++++---- src/torrentcontentmodel.cpp | 7 +++++-- src/torrentcontentmodel.h | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index c35c250a1..9d0a846f3 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -652,7 +652,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds() { bool PropertiesWidget::applyPriorities() { qDebug("Saving files priorities"); - const std::vector priorities = PropListModel->model()->getFilesPriorities(h.get_torrent_info().num_files()); + const std::vector priorities = PropListModel->model()->getFilesPriorities(); // Save first/last piece first option state bool first_last_piece_first = h.first_last_piece_first(); // Prioritize the files diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index 97ae051e8..d14482294 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -499,10 +499,10 @@ void torrentAdditionDialog::updateDiskSpaceLabels() { // Determine torrent size qulonglong torrent_size = 0; if (t->num_files() > 1) { - const unsigned int nbFiles = t->num_files(); - const std::vector priorities = PropListModel->model()->getFilesPriorities(nbFiles); + const std::vector priorities = PropListModel->model()->getFilesPriorities(); + Q_ASSERT(priorities.size() == t->num_files()); - for (unsigned int i=0; i 0) torrent_size += t->file_at(i).size; } @@ -596,7 +596,7 @@ bool torrentAdditionDialog::allFiltered() const { void torrentAdditionDialog::savePiecesPriorities() { qDebug("Saving pieces priorities"); Q_ASSERT(!is_magnet); - const std::vector priorities = PropListModel->model()->getFilesPriorities(t->num_files()); + const std::vector priorities = PropListModel->model()->getFilesPriorities(); TorrentTempData::setFilesPriority(hash, priorities); } diff --git a/src/torrentcontentmodel.cpp b/src/torrentcontentmodel.cpp index 38c58210d..bb7ac73ae 100644 --- a/src/torrentcontentmodel.cpp +++ b/src/torrentcontentmodel.cpp @@ -50,6 +50,7 @@ void TorrentContentModel::updateFilesProgress(const std::vectorsetProgress(fp[i]); } @@ -59,16 +60,18 @@ void TorrentContentModel::updateFilesProgress(const std::vector &fprio) { emit layoutAboutToBeChanged(); + Q_ASSERT(m_filesIndex.size() == (int)fprio.size()); + if (m_filesIndex.size() != (int)fprio.size()) return; for (uint i=0; isetPriority(fprio[i]); } emit dataChanged(index(0,0), index(rowCount(), columnCount())); } -std::vector TorrentContentModel::getFilesPriorities(unsigned int nbFiles) const +std::vector TorrentContentModel::getFilesPriorities() const { std::vector prio; - for (uint i=0; igetPriority()); } return prio; diff --git a/src/torrentcontentmodel.h b/src/torrentcontentmodel.h index 9f3988dcf..6651ab758 100644 --- a/src/torrentcontentmodel.h +++ b/src/torrentcontentmodel.h @@ -47,7 +47,7 @@ public: void updateFilesProgress(const std::vector& fp); void updateFilesPriorities(const std::vector &fprio); - std::vector getFilesPriorities(unsigned int nbFiles) const; + std::vector getFilesPriorities() const; bool allFiltered() const; virtual int columnCount(const QModelIndex &parent=QModelIndex()) const; virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);