mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +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:
parent
6c66d02aff
commit
ccb59fbad3
@ -83,13 +83,13 @@ MagnetUri::MagnetUri(const QString &source)
|
|||||||
|
|
||||||
m_name = QString::fromStdString(m_addTorrentParams.name);
|
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)
|
for (const std::string &tracker : m_addTorrentParams.trackers)
|
||||||
m_trackers.append({QString::fromStdString(tracker)});
|
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)
|
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
|
bool MagnetUri::isValid() const
|
||||||
|
@ -4830,7 +4830,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
|
|||||||
void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
|
void Session::handleStateUpdateAlert(const lt::state_update_alert *p)
|
||||||
{
|
{
|
||||||
QVector<Torrent *> updatedTorrents;
|
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)
|
for (const lt::torrent_status &status : p->status)
|
||||||
{
|
{
|
||||||
|
@ -112,8 +112,8 @@ namespace
|
|||||||
QString firstTrackerMessage;
|
QString firstTrackerMessage;
|
||||||
QString firstErrorMessage;
|
QString firstErrorMessage;
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
||||||
const int numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1);
|
const size_t numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1);
|
||||||
trackerEntry.endpoints.reserve(numEndpoints);
|
trackerEntry.endpoints.reserve(static_cast<decltype(trackerEntry.endpoints)::size_type>(numEndpoints));
|
||||||
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
|
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
|
||||||
{
|
{
|
||||||
for (const auto protocolVersion : {lt::protocol_version::V1, lt::protocol_version::V2})
|
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();
|
const std::vector<lt::announce_entry> nativeTrackers = m_nativeHandle.trackers();
|
||||||
|
|
||||||
QVector<TrackerEntry> entries;
|
QVector<TrackerEntry> entries;
|
||||||
entries.reserve(nativeTrackers.size());
|
entries.reserve(static_cast<decltype(entries)::size_type>(nativeTrackers.size()));
|
||||||
|
|
||||||
for (const lt::announce_entry &tracker : nativeTrackers)
|
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();
|
const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
|
||||||
|
|
||||||
QVector<QUrl> urlSeeds;
|
QVector<QUrl> urlSeeds;
|
||||||
urlSeeds.reserve(currentSeeds.size());
|
urlSeeds.reserve(static_cast<decltype(urlSeeds)::size_type>(currentSeeds.size()));
|
||||||
|
|
||||||
for (const std::string &urlSeed : currentSeeds)
|
for (const std::string &urlSeed : currentSeeds)
|
||||||
urlSeeds.append(QUrl(urlSeed.c_str()));
|
urlSeeds.append(QString::fromStdString(urlSeed));
|
||||||
|
|
||||||
return urlSeeds;
|
return urlSeeds;
|
||||||
}
|
}
|
||||||
@ -1223,9 +1223,11 @@ QVector<PeerInfo> TorrentImpl::peers() const
|
|||||||
m_nativeHandle.get_peer_info(nativePeers);
|
m_nativeHandle.get_peer_info(nativePeers);
|
||||||
|
|
||||||
QVector<PeerInfo> peers;
|
QVector<PeerInfo> peers;
|
||||||
peers.reserve(nativePeers.size());
|
peers.reserve(static_cast<decltype(peers)::size_type>(nativePeers.size()));
|
||||||
|
|
||||||
for (const lt::peer_info &peer : nativePeers)
|
for (const lt::peer_info &peer : nativePeers)
|
||||||
peers << PeerInfo(this, peer);
|
peers << PeerInfo(this, peer);
|
||||||
|
|
||||||
return peers;
|
return peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,10 +306,11 @@ QVector<TrackerEntry> TorrentInfo::trackers() const
|
|||||||
const std::vector<lt::announce_entry> trackers = m_nativeInfo->trackers();
|
const std::vector<lt::announce_entry> trackers = m_nativeInfo->trackers();
|
||||||
|
|
||||||
QVector<TrackerEntry> ret;
|
QVector<TrackerEntry> ret;
|
||||||
ret.reserve(trackers.size());
|
ret.reserve(static_cast<decltype(ret)::size_type>(trackers.size()));
|
||||||
|
|
||||||
for (const lt::announce_entry &tracker : trackers)
|
for (const lt::announce_entry &tracker : trackers)
|
||||||
ret.append({QString::fromStdString(tracker.url)});
|
ret.append({QString::fromStdString(tracker.url)});
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +321,7 @@ QVector<QUrl> TorrentInfo::urlSeeds() const
|
|||||||
const std::vector<lt::web_seed_entry> &nativeWebSeeds = m_nativeInfo->web_seeds();
|
const std::vector<lt::web_seed_entry> &nativeWebSeeds = m_nativeInfo->web_seeds();
|
||||||
|
|
||||||
QVector<QUrl> urlSeeds;
|
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)
|
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()))
|
if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount()))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const std::vector<lt::file_slice> files(
|
const std::vector<lt::file_slice> files = nativeInfo()->map_block(
|
||||||
nativeInfo()->map_block(lt::piece_index_t {pieceIndex}, 0
|
lt::piece_index_t {pieceIndex}, 0, nativeInfo()->piece_size(lt::piece_index_t {pieceIndex}));
|
||||||
, nativeInfo()->piece_size(lt::piece_index_t {pieceIndex})));
|
|
||||||
QVector<int> res;
|
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),
|
std::transform(files.begin(), files.end(), std::back_inserter(res),
|
||||||
[](const lt::file_slice &s) { return static_cast<int>(s.file_index); });
|
[](const lt::file_slice &s) { return static_cast<int>(s.file_index); });
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace
|
|||||||
QVector<T> loadFromBuffer(const boost::circular_buffer_space_optimized<T> &src, const int offset = 0)
|
QVector<T> loadFromBuffer(const boost::circular_buffer_space_optimized<T> &src, const int offset = 0)
|
||||||
{
|
{
|
||||||
QVector<T> ret;
|
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));
|
std::copy((src.begin() + offset), src.end(), std::back_inserter(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ QVector<Log::Msg> Logger::getMessages(const int lastKnownId) const
|
|||||||
const QReadLocker locker(&m_lock);
|
const QReadLocker locker(&m_lock);
|
||||||
|
|
||||||
const int diff = m_msgCounter - lastKnownId - 1;
|
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))
|
if ((lastKnownId == -1) || (diff >= size))
|
||||||
return loadFromBuffer(m_messages);
|
return loadFromBuffer(m_messages);
|
||||||
@ -111,7 +111,7 @@ QVector<Log::Peer> Logger::getPeers(const int lastKnownId) const
|
|||||||
const QReadLocker locker(&m_lock);
|
const QReadLocker locker(&m_lock);
|
||||||
|
|
||||||
const int diff = m_peerCounter - lastKnownId - 1;
|
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))
|
if ((lastKnownId == -1) || (diff >= size))
|
||||||
return loadFromBuffer(m_peers);
|
return loadFromBuffer(m_peers);
|
||||||
|
@ -79,7 +79,7 @@ BaseLogModel::BaseLogModel(QObject *parent)
|
|||||||
|
|
||||||
int BaseLogModel::rowCount(const QModelIndex &) const
|
int BaseLogModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
return m_messages.size();
|
return static_cast<int>(m_messages.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseLogModel::columnCount(const QModelIndex &) const
|
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.
|
// but because of calling of beginInsertRows function we'll have ghost rows.
|
||||||
if (m_messages.size() == MAX_VISIBLE_MESSAGES)
|
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);
|
beginRemoveRows(QModelIndex(), lastMessage, lastMessage);
|
||||||
m_messages.pop_back();
|
m_messages.pop_back();
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
@ -317,7 +317,7 @@ TagModelItem *TagFilterModel::findItem(const QString &tag)
|
|||||||
QVector<TagModelItem *> TagFilterModel::findItems(const TagSet &tags)
|
QVector<TagModelItem *> TagFilterModel::findItems(const TagSet &tags)
|
||||||
{
|
{
|
||||||
QVector<TagModelItem *> items;
|
QVector<TagModelItem *> items;
|
||||||
items.reserve(tags.size());
|
items.reserve(tags.count());
|
||||||
for (const QString &tag : tags)
|
for (const QString &tag : tags)
|
||||||
{
|
{
|
||||||
TagModelItem *item = findItem(tag);
|
TagModelItem *item = findItem(tag);
|
||||||
|
Loading…
Reference in New Issue
Block a user