diff --git a/src/run.rs b/src/run.rs
index 8ba32bd..f3c8114 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -160,16 +160,20 @@ impl Run {
/// Remaining seconds in the current state. During Running this is
/// `duration - elapsed` (clamped at 0). During Cooldown it's
- /// `remaining - elapsed` (clamped at 0). None when Done.
+ /// `remaining - elapsed` (clamped at 0). None when Done. Uses
+ /// `saturating_sub` because Duration subtraction panics on overflow
+ /// (happens when a workload overruns its duration — e.g. 7z which
+ /// isn't time-bound + runs until the run loop's stop() kicks in).
pub fn remaining_secs(&self) -> Option<f64> {
+ let elapsed = self.state_start.elapsed();
match &self.state {
State::Cooldown { remaining } => {
let dur = Duration::from_secs(*remaining);
- Some((dur - self.state_start.elapsed()).as_secs_f64().max(0.0))
+ Some(dur.saturating_sub(elapsed).as_secs_f64())
}
State::Running { duration_secs } => {
let dur = Duration::from_secs(*duration_secs);
- Some((dur - self.state_start.elapsed()).as_secs_f64().max(0.0))
+ Some(dur.saturating_sub(elapsed).as_secs_f64())
}
State::Done => None,
}
Fix Duration subtraction panic when workload overruns its duration
remaining_secs() did (dur - elapsed).max(0.0) — the subtraction panics on overflow (elapsed > dur) before the .max(0.0) can clamp. Happens when a workload overruns its duration (e.g. 7z which isn't time-bound + runs until the run loop's stop() kicks in, or stress-ng at the boundary race). Fix: dur.saturating_sub(elapsed) — returns zero on overflow instead of panicking.
f023dc273e0fa2b98f9da38731df22569100a7dd
josie <administrator@josie-c.com> · 2026-09-01T22:05 ·
browse files at this commit
parents:
b79a210