batch_timeout: fix overflowing subtraction (#1976)

This commit is contained in:
s1341 2024-03-28 17:50:12 +02:00 committed by GitHub
parent c221108916
commit 1fc5ba63fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -324,10 +324,10 @@ impl TimerStruct {
pub fn unset_timer(&mut self) { pub fn unset_timer(&mut self) {
if self.batch_mode { if self.batch_mode {
unsafe { unsafe {
let elapsed = current_time() - self.tmout_start_time; let elapsed = current_time().saturating_sub(self.tmout_start_time);
// elapsed may be > than tmout in case of received but ingored signal // elapsed may be > than tmout in case of received but ingored signal
if elapsed > self.exec_tmout if elapsed > self.exec_tmout
|| self.exec_tmout - elapsed < self.avg_exec_time * self.avg_mul_k || self.exec_tmout.saturating_sub(elapsed) < self.avg_exec_time * self.avg_mul_k
{ {
let disarmed: libc::itimerspec = zeroed(); let disarmed: libc::itimerspec = zeroed();
libc::timer_settime(self.timerid, 0, addr_of!(disarmed), null_mut()); libc::timer_settime(self.timerid, 0, addr_of!(disarmed), null_mut());