refactor: harden idle_seconds (#6834)

* Hardening idle_seconds

* code review: revert "size_t to time_t" because time_t isn't guaranted to be signed in the C spec
This commit is contained in:
Cœur 2024-06-02 06:41:44 +08:00 committed by GitHub
parent 78027a8e5b
commit acee39e15c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -446,7 +446,7 @@ void tr_torrent::stop_if_seed_limit_reached()
session->onRatioLimitHit(this); session->onRatioLimitHit(this);
} }
/* if we're seeding and reach our inactivity limit, stop the torrent */ /* if we're seeding and reach our inactivity limit, stop the torrent */
else if (auto const secs_left = idle_seconds_left(tr_time()); secs_left && *secs_left == 0U) else if (auto const secs_left = idle_seconds_left(tr_time()); secs_left && *secs_left <= 0U)
{ {
tr_logAddInfoTor(this, _("Seeding idle limit reached; pausing torrent")); tr_logAddInfoTor(this, _("Seeding idle limit reached; pausing torrent"));

View File

@ -827,7 +827,7 @@ struct tr_torrent
if (auto const latest = std::max(date_started_, date_active_); latest != 0) if (auto const latest = std::max(date_started_, date_active_); latest != 0)
{ {
TR_ASSERT(now >= latest); TR_ASSERT(now >= latest);
return now - latest; return static_cast<size_t>(std::max(now - latest, time_t{ 0 }));
} }
} }