diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 60d0fc4b8..a95a99af8 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -208,11 +208,10 @@ qlonglong PeerInfo::totalDownload() const QBitArray PeerInfo::pieces() const { QBitArray result(m_nativeInfo.pieces.size()); - - int i = 0; - for (const bool bit : m_nativeInfo.pieces) - result.setBit(i++, bit); - + for (int i = 0; i < result.size(); ++i) { + if (m_nativeInfo.pieces[i]) + result.setBit(i, true); + } return result; } diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 8a8e4fd71..44d48ee36 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1202,10 +1202,10 @@ QVector TorrentHandle::peers() const QBitArray TorrentHandle::pieces() const { QBitArray result(m_nativeStatus.pieces.size()); - - for (int i = 0; i < m_nativeStatus.pieces.size(); ++i) - result.setBit(i, m_nativeStatus.pieces.get_bit(LTPieceIndex {i})); - + for (int i = 0; i < result.size(); ++i) { + if (m_nativeStatus.pieces[LTPieceIndex {i}]) + result.setBit(i, true); + } return result; }