From d7babab6ba621a384fdfe5950a26bf76a396faf4 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Fri, 9 Jan 2026 21:25:30 +0800 Subject: [PATCH] refactor: convert `tr_bandwidth::RateControl::newest_` to unsigned (#8094) --- libtransmission/bandwidth.cc | 10 +++++----- libtransmission/bandwidth.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libtransmission/bandwidth.cc b/libtransmission/bandwidth.cc index c71e3978f..3a8d6799e 100644 --- a/libtransmission/bandwidth.cc +++ b/libtransmission/bandwidth.cc @@ -39,18 +39,18 @@ Speed tr_bandwidth::get_speed(RateControl& r, unsigned int interval_msec, uint64 uint64_t bytes = 0U; uint64_t const cutoff = now - interval_msec; - for (int i = r.newest_; r.date_[i] > cutoff;) + for (auto i = r.newest_; r.date_[i] > cutoff;) { bytes += r.size_[i]; - if (--i == -1) + if (--i >= HistorySize) // overflowed below zero { - i = HistorySize - 1; /* circular history */ + i = HistorySize - 1U; // circular history } if (i == r.newest_) { - break; /* we've come all the way around */ + break; // we've come all the way around } } @@ -71,7 +71,7 @@ void tr_bandwidth::notify_bandwidth_consumed_bytes(uint64_t const now, RateContr { if (++r.newest_ == HistorySize) { - r.newest_ = 0; + r.newest_ = 0U; } r.date_[r.newest_] = now; diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index a4e1e58af..861ab3966 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -237,7 +237,7 @@ private: std::array size_; uint64_t cache_time_; Speed cache_val_; - int newest_; + size_t newest_; }; struct Band