Clamp the elapsed time conversion instead of overflowing.

convert.elapsed_time subtracted an unchecked value from the cached seconds.
This commit is contained in:
xirvik
2026-08-21 16:02:07 +00:00
committed by Jari Sundell
parent dcfbf82a38
commit d7b2cfe4f2
+2 -1
View File
@@ -408,8 +408,9 @@ apply_to_time(const torrent::Object& rawArgs, int flags) {
torrent::Object
apply_to_elapsed_time(const torrent::Object& rawArgs) {
auto cached_seconds = torrent::this_thread::cached_seconds().count();
auto value = rawArgs.as_value();
uint64_t arg = cached_seconds - rawArgs.as_value();
uint64_t arg = value >= 0 && value <= cached_seconds ? cached_seconds - value : 0;
char buffer[48];
snprintf(buffer, 48, "%2d:%02d:%02d", (int)(arg / 3600), (int)((arg / 60) % 60), (int)(arg % 60));