From 562080de697e08e8ade89ea37403bebcd6850a08 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 20 May 2017 11:38:39 +0800 Subject: [PATCH 1/2] Initialize variable Fixes coverity CID 161628 --- src/base/utils/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/utils/version.h b/src/base/utils/version.h index ca708f524..aa1be88d1 100644 --- a/src/base/utils/version.h +++ b/src/base/utils/version.h @@ -167,7 +167,7 @@ namespace Utils throw std::runtime_error ("Incorrect number of version components"); bool ok = false; - ComponentsArray res; + ComponentsArray res{}; for (std::size_t i = 0; i < static_cast(versionParts.size()); ++i) { res[i] = static_cast(versionParts[i].toInt(&ok)); if (!ok) From d8c0a40b1f46a1dbc1a4b3d045b23c6992fd46e4 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 20 May 2017 14:01:58 +0800 Subject: [PATCH 2/2] Add explicit error handling when filesCount() returns negative value Fix coverity CID 162538 --- src/base/bittorrent/torrenthandle.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 6214aeb58..bb9ec3739 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -2053,8 +2053,10 @@ void TorrentHandle::prioritizeFiles(const QVector &priorities) QVector TorrentHandle::availableFileFractions() const { - QVector piecesAvailability = pieceAvailability(); const auto filesCount = this->filesCount(); + if (filesCount < 0) return {}; + + const QVector piecesAvailability = pieceAvailability(); // libtorrent returns empty array for seeding only torrents if (piecesAvailability.empty()) return QVector(filesCount, -1.);