Browse Source

Fix crash when a fastresume file is empty (closes #52)

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
d2a6887248
  1. 7
      src/qtlibtorrent/qbtsession.cpp

7
src/qtlibtorrent/qbtsession.cpp

@ -869,11 +869,16 @@ bool QBtSession::loadFastResumeData(const QString &hash, std::vector<char> &buf)
const QString fastresume_path = QDir(fsutils::BTBackupLocation()).absoluteFilePath(hash+QString(".fastresume")); const QString fastresume_path = QDir(fsutils::BTBackupLocation()).absoluteFilePath(hash+QString(".fastresume"));
qDebug("Trying to load fastresume data: %s", qPrintable(fastresume_path)); qDebug("Trying to load fastresume data: %s", qPrintable(fastresume_path));
QFile fastresume_file(fastresume_path); QFile fastresume_file(fastresume_path);
if (!fastresume_file.open(QIODevice::ReadOnly)) return false; if (fastresume_file.size() <= 0)
return false;
if (!fastresume_file.open(QIODevice::ReadOnly))
return false;
const QByteArray content = fastresume_file.readAll(); const QByteArray content = fastresume_file.readAll();
const int content_size = content.size(); const int content_size = content.size();
Q_ASSERT(content_size > 0);
buf.resize(content_size); buf.resize(content_size);
memcpy(&buf[0], content.data(), content_size); memcpy(&buf[0], content.data(), content_size);
fastresume_file.close();
return true; return true;
} }

Loading…
Cancel
Save