diff --git a/src/base/bittorrent/torrenthandleimpl.cpp b/src/base/bittorrent/torrenthandleimpl.cpp index 85f6f13cd..a0a75cfd1 100644 --- a/src/base/bittorrent/torrenthandleimpl.cpp +++ b/src/base/bittorrent/torrenthandleimpl.cpp @@ -2120,7 +2120,7 @@ void TorrentHandleImpl::prioritizeFiles(const QVector &priorit QVector TorrentHandleImpl::availableFileFractions() const { const int filesCount = this->filesCount(); - if (filesCount < 0) return {}; + if (filesCount <= 0) return {}; const QVector piecesAvailability = pieceAvailability(); // libtorrent returns empty array for seeding only torrents @@ -2136,7 +2136,10 @@ QVector TorrentHandleImpl::availableFileFractions() const for (const int piece : filePieces) availablePieces += (piecesAvailability[piece] > 0) ? 1 : 0; - res.push_back(static_cast(availablePieces) / filePieces.size()); + const qreal availability = filePieces.isEmpty() + ? 1 // the file has no pieces, so it is available by default + : static_cast(availablePieces) / filePieces.size(); + res.push_back(availability); } return res; }