1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 23:07:59 +00:00

Suppress C4267 conversion warnings (#13307)

- warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data

Caused by mismatch between size_type of std and Qt containers. It is safe to cast to int as all of those containers hold low number of objects.
This commit is contained in:
Kacper Michajłow 2021-06-11 07:51:06 +02:00 committed by GitHub
parent 6c66d02aff
commit ccb59fbad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 22 deletions

View File

@ -83,13 +83,13 @@ MagnetUri::MagnetUri(const QString &source)
m_name = QString::fromStdString(m_addTorrentParams.name);
m_trackers.reserve(m_addTorrentParams.trackers.size());
m_trackers.reserve(static_cast<decltype(m_trackers)::size_type>(m_addTorrentParams.trackers.size()));
for (const std::string &tracker : m_addTorrentParams.trackers)
m_trackers.append({QString::fromStdString(tracker)});
m_urlSeeds.reserve(m_addTorrentParams.url_seeds.size());
m_urlSeeds.reserve(static_cast<decltype(m_urlSeeds)::size_type>(m_addTorrentParams.url_seeds.size()));
for (const std::string &urlSeed : m_addTorrentParams.url_seeds)
m_urlSeeds.append(QUrl(QString::fromStdString(urlSeed)));
m_urlSeeds.append(QString::fromStdString(urlSeed));
}
bool MagnetUri::isValid() const

View File

@ -4830,7 +4830,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
{
QVector<Torrent *> updatedTorrents;
updatedTorrents.reserve(p->status.size());
updatedTorrents.reserve(static_cast<decltype(updatedTorrents)::size_type>(p->status.size()));
for (const lt::torrent_status &status : p->status)
{

View File

@ -112,8 +112,8 @@ namespace
QString firstTrackerMessage;
QString firstErrorMessage;
#if (LIBTORRENT_VERSION_NUM >= 20000)
const int numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1);
trackerEntry.endpoints.reserve(numEndpoints);
const size_t numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1);
trackerEntry.endpoints.reserve(static_cast<decltype(trackerEntry.endpoints)::size_type>(numEndpoints));
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
{
for (const auto protocolVersion : {lt::protocol_version::V1, lt::protocol_version::V2})
@ -473,7 +473,7 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
const std::vector<lt::announce_entry> nativeTrackers = m_nativeHandle.trackers();
QVector<TrackerEntry> entries;
entries.reserve(nativeTrackers.size());
entries.reserve(static_cast<decltype(entries)::size_type>(nativeTrackers.size()));
for (const lt::announce_entry &tracker : nativeTrackers)
{
@ -560,10 +560,10 @@ QVector<QUrl> TorrentImpl::urlSeeds() const
const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
QVector<QUrl> urlSeeds;
urlSeeds.reserve(currentSeeds.size());
urlSeeds.reserve(static_cast<decltype(urlSeeds)::size_type>(currentSeeds.size()));
for (const std::string &urlSeed : currentSeeds)
urlSeeds.append(QUrl(urlSeed.c_str()));
urlSeeds.append(QString::fromStdString(urlSeed));
return urlSeeds;
}
@ -1223,9 +1223,11 @@ QVector<PeerInfo> TorrentImpl::peers() const
m_nativeHandle.get_peer_info(nativePeers);
QVector<PeerInfo> peers;
peers.reserve(nativePeers.size());
peers.reserve(static_cast<decltype(peers)::size_type>(nativePeers.size()));
for (const lt::peer_info &peer : nativePeers)
peers << PeerInfo(this, peer);
return peers;
}

View File

@ -306,10 +306,11 @@ QVector<TrackerEntry> TorrentInfo::trackers() const
const std::vector<lt::announce_entry> trackers = m_nativeInfo->trackers();
QVector<TrackerEntry> ret;
ret.reserve(trackers.size());
ret.reserve(static_cast<decltype(ret)::size_type>(trackers.size()));
for (const lt::announce_entry &tracker : trackers)
ret.append({QString::fromStdString(tracker.url)});
return ret;
}
@ -320,7 +321,7 @@ QVector<QUrl> TorrentInfo::urlSeeds() const
const std::vector<lt::web_seed_entry> &nativeWebSeeds = m_nativeInfo->web_seeds();
QVector<QUrl> urlSeeds;
urlSeeds.reserve(nativeWebSeeds.size());
urlSeeds.reserve(static_cast<decltype(urlSeeds)::size_type>(nativeWebSeeds.size()));
for (const lt::web_seed_entry &webSeed : nativeWebSeeds)
{
@ -360,11 +361,10 @@ QVector<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const
if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount()))
return {};
const std::vector<lt::file_slice> files(
nativeInfo()->map_block(lt::piece_index_t {pieceIndex}, 0
, nativeInfo()->piece_size(lt::piece_index_t {pieceIndex})));
const std::vector<lt::file_slice> files = nativeInfo()->map_block(
lt::piece_index_t {pieceIndex}, 0, nativeInfo()->piece_size(lt::piece_index_t {pieceIndex}));
QVector<int> res;
res.reserve(int(files.size()));
res.reserve(static_cast<decltype(res)::size_type>(files.size()));
std::transform(files.begin(), files.end(), std::back_inserter(res),
[](const lt::file_slice &s) { return static_cast<int>(s.file_index); });

View File

@ -39,7 +39,7 @@ namespace
QVector<T> loadFromBuffer(const boost::circular_buffer_space_optimized<T> &src, const int offset = 0)
{
QVector<T> ret;
ret.reserve(src.size() - offset);
ret.reserve(static_cast<typename decltype(ret)::size_type>(src.size()) - offset);
std::copy((src.begin() + offset), src.end(), std::back_inserter(ret));
return ret;
}
@ -95,7 +95,7 @@ QVector<Log::Msg> Logger::getMessages(const int lastKnownId) const
const QReadLocker locker(&m_lock);
const int diff = m_msgCounter - lastKnownId - 1;
const int size = m_messages.size();
const int size = static_cast<int>(m_messages.size());
if ((lastKnownId == -1) || (diff >= size))
return loadFromBuffer(m_messages);
@ -111,7 +111,7 @@ QVector<Log::Peer> Logger::getPeers(const int lastKnownId) const
const QReadLocker locker(&m_lock);
const int diff = m_peerCounter - lastKnownId - 1;
const int size = m_peers.size();
const int size = static_cast<int>(m_peers.size());
if ((lastKnownId == -1) || (diff >= size))
return loadFromBuffer(m_peers);

View File

@ -79,7 +79,7 @@ BaseLogModel::BaseLogModel(QObject *parent)
int BaseLogModel::rowCount(const QModelIndex &) const
{
return m_messages.size();
return static_cast<int>(m_messages.size());
}
int BaseLogModel::columnCount(const QModelIndex &) const
@ -120,7 +120,7 @@ void BaseLogModel::addNewMessage(const BaseLogModel::Message &message)
// but because of calling of beginInsertRows function we'll have ghost rows.
if (m_messages.size() == MAX_VISIBLE_MESSAGES)
{
const int lastMessage = m_messages.size() - 1;
const int lastMessage = static_cast<int>(m_messages.size()) - 1;
beginRemoveRows(QModelIndex(), lastMessage, lastMessage);
m_messages.pop_back();
endRemoveRows();

View File

@ -317,7 +317,7 @@ TagModelItem *TagFilterModel::findItem(const QString &tag)
QVector<TagModelItem *> TagFilterModel::findItems(const TagSet &tags)
{
QVector<TagModelItem *> items;
items.reserve(tags.size());
items.reserve(tags.count());
for (const QString &tag : tags)
{
TagModelItem *item = findItem(tag);