diff --git a/src/torrent.cpp b/src/torrent.cpp index de666ec75..6a90aa21a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -10835,11 +10835,15 @@ bool is_downloading_state(int const st) { TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(b > 0); - TORRENT_ASSERT(m_total_redundant_bytes <= std::numeric_limits::max() - b); - m_total_redundant_bytes += b; - TORRENT_ASSERT(static_cast(reason) >= 0); TORRENT_ASSERT(static_cast(reason) < static_cast(waste_reason::max)); + + if (m_total_redundant_bytes <= std::numeric_limits::max() - b) + m_total_redundant_bytes += b; + else + m_total_redundant_bytes = std::numeric_limits::max(); + + // the stats counters are 64 bits, so we don't check for overflow there m_stats_counters.inc_stats_counter(counters::recv_redundant_bytes, b); m_stats_counters.inc_stats_counter(counters::waste_piece_timed_out + static_cast(reason), b); } @@ -10848,8 +10852,12 @@ bool is_downloading_state(int const st) { TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(b > 0); - TORRENT_ASSERT(m_total_failed_bytes <= std::numeric_limits::max() - b); - m_total_failed_bytes += b; + if (m_total_failed_bytes <= std::numeric_limits::max() - b) + m_total_failed_bytes += b; + else + m_total_failed_bytes = std::numeric_limits::max(); + + // the stats counters are 64 bits, so we don't check for overflow there m_stats_counters.inc_stats_counter(counters::recv_failed_bytes, b); }