Browse Source

Add more vector length checks

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
a940917144
  1. 2
      src/properties/propertieswidget.cpp
  2. 8
      src/torrentadditiondlg.cpp
  3. 7
      src/torrentcontentmodel.cpp
  4. 2
      src/torrentcontentmodel.h

2
src/properties/propertieswidget.cpp

@ -652,7 +652,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds() { @@ -652,7 +652,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds() {
bool PropertiesWidget::applyPriorities() {
qDebug("Saving files priorities");
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities(h.get_torrent_info().num_files());
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities();
// Save first/last piece first option state
bool first_last_piece_first = h.first_last_piece_first();
// Prioritize the files

8
src/torrentadditiondlg.cpp

@ -499,10 +499,10 @@ void torrentAdditionDialog::updateDiskSpaceLabels() { @@ -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<int> priorities = PropListModel->model()->getFilesPriorities(nbFiles);
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities();
Q_ASSERT(priorities.size() == t->num_files());
for (unsigned int i=0; i<nbFiles; ++i) {
for (unsigned int i=0; i<priorities.size(); ++i) {
if (priorities[i] > 0)
torrent_size += t->file_at(i).size;
}
@ -596,7 +596,7 @@ bool torrentAdditionDialog::allFiltered() const { @@ -596,7 +596,7 @@ bool torrentAdditionDialog::allFiltered() const {
void torrentAdditionDialog::savePiecesPriorities() {
qDebug("Saving pieces priorities");
Q_ASSERT(!is_magnet);
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities(t->num_files());
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities();
TorrentTempData::setFilesPriority(hash, priorities);
}

7
src/torrentcontentmodel.cpp

@ -50,6 +50,7 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size @@ -50,6 +50,7 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size
{
emit layoutAboutToBeChanged();
Q_ASSERT(m_filesIndex.size() == (int)fp.size());
if (m_filesIndex.size() != (int)fp.size()) return;
for (uint i=0; i<fp.size(); ++i) {
m_filesIndex[i]->setProgress(fp[i]);
}
@ -59,16 +60,18 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size @@ -59,16 +60,18 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size
void TorrentContentModel::updateFilesPriorities(const std::vector<int> &fprio)
{
emit layoutAboutToBeChanged();
Q_ASSERT(m_filesIndex.size() == (int)fprio.size());
if (m_filesIndex.size() != (int)fprio.size()) return;
for (uint i=0; i<fprio.size(); ++i) {
m_filesIndex[i]->setPriority(fprio[i]);
}
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
}
std::vector<int> TorrentContentModel::getFilesPriorities(unsigned int nbFiles) const
std::vector<int> TorrentContentModel::getFilesPriorities() const
{
std::vector<int> prio;
for (uint i=0; i<nbFiles; ++i) {
for (uint i=0; i<m_filesIndex.size(); ++i) {
prio.push_back(m_filesIndex[i]->getPriority());
}
return prio;

2
src/torrentcontentmodel.h

@ -47,7 +47,7 @@ public: @@ -47,7 +47,7 @@ public:
void updateFilesProgress(const std::vector<libtorrent::size_type>& fp);
void updateFilesPriorities(const std::vector<int> &fprio);
std::vector<int> getFilesPriorities(unsigned int nbFiles) const;
std::vector<int> 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);

Loading…
Cancel
Save