Fix "Implicit conversion loses integer precision" (#4194)
This commit is contained in:
parent
76bea25f6e
commit
d26db72d7e
|
@ -1545,7 +1545,7 @@ void tr_announcer_impl::upkeep()
|
|||
****
|
||||
***/
|
||||
|
||||
static tr_tracker_view trackerView(tr_torrent const& tor, int tier_index, tr_tier const& tier, tr_tracker const& tracker)
|
||||
static tr_tracker_view trackerView(tr_torrent const& tor, size_t tier_index, tr_tier const& tier, tr_tracker const& tracker)
|
||||
{
|
||||
auto const now = tr_time();
|
||||
auto view = tr_tracker_view{};
|
||||
|
|
|
@ -147,7 +147,7 @@ void tr_bandwidth::allocateBandwidth(
|
|||
auto bandwidth = &this->band_[dir];
|
||||
if (bandwidth->is_limited_)
|
||||
{
|
||||
uint64_t const next_pulse_speed = bandwidth->desired_speed_bps_;
|
||||
auto const next_pulse_speed = bandwidth->desired_speed_bps_;
|
||||
bandwidth->bytes_left_ = next_pulse_speed * period_msec / 1000U;
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ void tr_bandwidth::allocate(tr_direction dir, unsigned int period_msec)
|
|||
****
|
||||
***/
|
||||
|
||||
unsigned int tr_bandwidth::clamp(uint64_t now, tr_direction dir, unsigned int byte_count) const
|
||||
size_t tr_bandwidth::clamp(uint64_t now, tr_direction dir, size_t byte_count) const
|
||||
{
|
||||
TR_ASSERT(tr_isDirection(dir));
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public:
|
|||
/**
|
||||
* @brief clamps byte_count down to a number that this bandwidth will allow to be consumed
|
||||
*/
|
||||
[[nodiscard]] unsigned int clamp(tr_direction dir, unsigned int byte_count) const noexcept
|
||||
[[nodiscard]] size_t clamp(tr_direction dir, size_t byte_count) const noexcept
|
||||
{
|
||||
return this->clamp(0, dir, byte_count);
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ public:
|
|||
{
|
||||
RateControl raw_;
|
||||
RateControl piece_;
|
||||
unsigned int bytes_left_;
|
||||
size_t bytes_left_;
|
||||
tr_bytes_per_second_t desired_speed_bps_;
|
||||
bool is_limited_ = false;
|
||||
bool honor_parent_limits_ = true;
|
||||
|
@ -250,7 +250,7 @@ private:
|
|||
|
||||
static void notifyBandwidthConsumedBytes(uint64_t now, RateControl* r, size_t size);
|
||||
|
||||
[[nodiscard]] unsigned int clamp(uint64_t now, tr_direction dir, unsigned int byte_count) const;
|
||||
[[nodiscard]] size_t clamp(uint64_t now, tr_direction dir, size_t byte_count) const;
|
||||
|
||||
static void phaseOne(std::vector<tr_peerIo*>& peer_array, tr_direction dir);
|
||||
|
||||
|
|
|
@ -119,9 +119,14 @@ public:
|
|||
|
||||
void add(void const* data, size_t data_length) override
|
||||
{
|
||||
if (data_length > 0U)
|
||||
static auto constexpr Max = static_cast<size_t>(std::numeric_limits<CC_LONG>::max());
|
||||
auto const* sha_data = static_cast<uint8_t const*>(data);
|
||||
while (data_length > 0)
|
||||
{
|
||||
CC_SHA1_Update(&handle_, data, data_length);
|
||||
auto const n_bytes = static_cast<CC_LONG>(std::min(data_length, Max));
|
||||
CC_SHA1_Update(&handle_, sha_data, n_bytes);
|
||||
data_length -= n_bytes;
|
||||
sha_data += n_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,9 +159,14 @@ public:
|
|||
|
||||
void add(void const* data, size_t data_length) override
|
||||
{
|
||||
if (data_length > 0U)
|
||||
static auto constexpr Max = static_cast<size_t>(std::numeric_limits<CC_LONG>::max());
|
||||
auto const* sha_data = static_cast<uint8_t const*>(data);
|
||||
while (data_length > 0)
|
||||
{
|
||||
CC_SHA256_Update(&handle_, data, data_length);
|
||||
auto const n_bytes = static_cast<CC_LONG>(std::min(data_length, Max));
|
||||
CC_SHA256_Update(&handle_, sha_data, n_bytes);
|
||||
data_length -= n_bytes;
|
||||
sha_data += n_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -260,17 +260,17 @@ std::optional<tr_sha1_digest_t> recalculateHash(tr_torrent* tor, tr_piece_index_
|
|||
|
||||
} // namespace
|
||||
|
||||
int tr_ioRead(tr_torrent* tor, tr_block_info::Location loc, uint32_t len, uint8_t* setme)
|
||||
int tr_ioRead(tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t* setme)
|
||||
{
|
||||
return readOrWritePiece(tor, IoMode::Read, loc, setme, len);
|
||||
}
|
||||
|
||||
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, uint32_t len)
|
||||
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len)
|
||||
{
|
||||
return readOrWritePiece(tor, IoMode::Prefetch, loc, nullptr, len);
|
||||
}
|
||||
|
||||
int tr_ioWrite(tr_torrent* tor, tr_block_info::Location loc, uint32_t len, uint8_t const* writeme)
|
||||
int tr_ioWrite(tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t const* writeme)
|
||||
{
|
||||
return readOrWritePiece(tor, IoMode::Write, loc, const_cast<uint8_t*>(writeme), len);
|
||||
}
|
||||
|
|
|
@ -26,15 +26,15 @@ struct tr_torrent;
|
|||
* Reads the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioRead(struct tr_torrent* tor, tr_block_info::Location loc, uint32_t len, uint8_t* setme);
|
||||
int tr_ioRead(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t* setme);
|
||||
|
||||
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, uint32_t len);
|
||||
int tr_ioPrefetch(tr_torrent* tor, tr_block_info::Location loc, size_t len);
|
||||
|
||||
/**
|
||||
* Writes the block specified by the piece index, offset, and length.
|
||||
* @return 0 on success, or an errno value on failure.
|
||||
*/
|
||||
int tr_ioWrite(struct tr_torrent* tor, tr_block_info::Location loc, uint32_t len, uint8_t const* writeme);
|
||||
int tr_ioWrite(struct tr_torrent* tor, tr_block_info::Location loc, size_t len, uint8_t const* writeme);
|
||||
|
||||
/**
|
||||
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
|
||||
|
|
|
@ -203,7 +203,7 @@ static void event_read_cb(evutil_socket_t fd, short /*event*/, void* vio)
|
|||
io->pendingEvents &= ~EV_READ;
|
||||
|
||||
auto const curlen = io->readBufferSize();
|
||||
auto howmuch = static_cast<unsigned int>(curlen >= max ? 0 : max - curlen);
|
||||
auto howmuch = curlen >= max ? 0 : max - curlen;
|
||||
howmuch = io->bandwidth().clamp(TR_DOWN, howmuch);
|
||||
|
||||
tr_logAddTraceIo(io, "libevent says this peer is ready to read");
|
||||
|
@ -339,7 +339,7 @@ void tr_peerIo::readBufferAdd(void const* data, size_t n_bytes)
|
|||
|
||||
static size_t utp_get_rb_size(tr_peerIo* const io)
|
||||
{
|
||||
size_t const bytes = io->bandwidth().clamp(TR_DOWN, UtpReadBufferSize);
|
||||
auto const bytes = io->bandwidth().clamp(TR_DOWN, UtpReadBufferSize);
|
||||
|
||||
tr_logAddTraceIo(io, fmt::format("utp_get_rb_size is saying it's ready to read {} bytes", bytes));
|
||||
return UtpReadBufferSize - bytes;
|
||||
|
|
|
@ -238,7 +238,7 @@ std::optional<std::string> tr_session::WebMediator::publicAddressV6() const
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
unsigned int tr_session::WebMediator::clamp(int torrent_id, unsigned int byte_count) const
|
||||
size_t tr_session::WebMediator::clamp(int torrent_id, size_t byte_count) const
|
||||
{
|
||||
auto const lock = session_->unique_lock();
|
||||
|
||||
|
@ -1892,7 +1892,7 @@ bool tr_sessionGetQueueStalledEnabled(tr_session const* session)
|
|||
return session->queueStalledEnabled();
|
||||
}
|
||||
|
||||
int tr_sessionGetQueueStalledMinutes(tr_session const* session)
|
||||
size_t tr_sessionGetQueueStalledMinutes(tr_session const* session)
|
||||
{
|
||||
TR_ASSERT(session != nullptr);
|
||||
|
||||
|
@ -1971,7 +1971,7 @@ size_t tr_session::countQueueFreeSlots(tr_direction dir) const noexcept
|
|||
/* count how many torrents are active */
|
||||
auto active_count = size_t{};
|
||||
bool const stalled_enabled = queueStalledEnabled();
|
||||
int const stalled_if_idle_for_n_seconds = queueStalledMinutes() * 60;
|
||||
auto const stalled_if_idle_for_n_seconds = queueStalledMinutes() * 60;
|
||||
time_t const now = tr_time();
|
||||
for (auto const* const tor : torrents())
|
||||
{
|
||||
|
@ -1984,7 +1984,7 @@ size_t tr_session::countQueueFreeSlots(tr_direction dir) const noexcept
|
|||
/* is it stalled? */
|
||||
if (stalled_enabled)
|
||||
{
|
||||
auto const idle_secs = int(difftime(now, std::max(tor->startDate, tor->activityDate)));
|
||||
auto const idle_secs = static_cast<size_t>(difftime(now, std::max(tor->startDate, tor->activityDate)));
|
||||
if (idle_secs >= stalled_if_idle_for_n_seconds)
|
||||
{
|
||||
continue;
|
||||
|
|
|
@ -228,7 +228,7 @@ private:
|
|||
[[nodiscard]] std::optional<std::string> publicAddressV4() const override;
|
||||
[[nodiscard]] std::optional<std::string> publicAddressV6() const override;
|
||||
[[nodiscard]] std::optional<std::string_view> userAgent() const override;
|
||||
[[nodiscard]] unsigned int clamp(int torrent_id, unsigned int byte_count) const override;
|
||||
[[nodiscard]] size_t clamp(int torrent_id, size_t byte_count) const override;
|
||||
void notifyBandwidthConsumed(int torrent_id, size_t byte_count) override;
|
||||
// runs the tr_web::fetch response callback in the libtransmission thread
|
||||
void run(tr_web::FetchDoneFunc&& func, tr_web::FetchResponse&& response) const override;
|
||||
|
|
|
@ -77,7 +77,9 @@ bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size)
|
|||
return false;
|
||||
}
|
||||
|
||||
int const n = (size <= 0 || size > INT_MAX) ? -1 : size / METADATA_PIECE_SIZE + (size % METADATA_PIECE_SIZE != 0 ? 1 : 0);
|
||||
int const n = (size <= 0 || size > INT_MAX) ?
|
||||
-1 :
|
||||
static_cast<int>(size / METADATA_PIECE_SIZE + (size % METADATA_PIECE_SIZE != 0 ? 1 : 0));
|
||||
|
||||
tr_logAddDebugTor(tor, fmt::format("metadata is {} bytes in {} pieces", size, n));
|
||||
|
||||
|
|
|
@ -661,7 +661,7 @@ bool tr_sessionGetQueueEnabled(tr_session const*, tr_direction);
|
|||
void tr_sessionSetQueueStalledMinutes(tr_session*, int minutes);
|
||||
|
||||
/** @return the number of minutes a torrent can be idle before being considered as stalled */
|
||||
int tr_sessionGetQueueStalledMinutes(tr_session const*);
|
||||
size_t tr_sessionGetQueueStalledMinutes(tr_session const*);
|
||||
|
||||
/** @brief Set whether or not to count torrents idle for over N minutes as 'stalled' */
|
||||
void tr_sessionSetQueueStalledEnabled(tr_session*, bool);
|
||||
|
@ -1349,7 +1349,7 @@ struct tr_tracker_view
|
|||
int leecherCount; // number of leechers the tracker knows of, or -1 if unknown
|
||||
int seederCount; // number of seeders the tracker knows of, or -1 if unknown
|
||||
|
||||
int tier; // which tier this tracker is in
|
||||
size_t tier; // which tier this tracker is in
|
||||
tr_torrent_id_t id; // unique transmission-generated ID for use in libtransmission API
|
||||
|
||||
tr_tracker_state announceState; // whether we're announcing, waiting to announce, etc.
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
}
|
||||
|
||||
// Return the number of bytes that should be allowed. See tr_bandwidth::clamp()
|
||||
[[nodiscard]] virtual unsigned int clamp([[maybe_unused]] int bandwidth_tag, unsigned int byte_count) const
|
||||
[[nodiscard]] virtual size_t clamp([[maybe_unused]] int bandwidth_tag, size_t byte_count) const
|
||||
{
|
||||
return byte_count;
|
||||
}
|
||||
|
|
|
@ -1453,7 +1453,7 @@ static NSString* const kWebUIURLFormat = @"http://localhost:%ld/";
|
|||
BOOL const checkStalled = tr_sessionGetQueueStalledEnabled(self.fHandle);
|
||||
[self.fDefaults setBool:checkStalled forKey:@"CheckStalled"];
|
||||
|
||||
int const stalledMinutes = tr_sessionGetQueueStalledMinutes(self.fHandle);
|
||||
NSInteger const stalledMinutes = tr_sessionGetQueueStalledMinutes(self.fHandle);
|
||||
[self.fDefaults setInteger:stalledMinutes forKey:@"StalledMinutes"];
|
||||
|
||||
//done script
|
||||
|
|
Loading…
Reference in New Issue