1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Add more vector length checks

This commit is contained in:
Christophe Dumez 2012-04-08 11:17:32 +03:00
parent 7bd4a1b849
commit a940917144
4 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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 {
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);
}

View File

@ -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
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;

View File

@ -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);