diff --git a/src/menu.rs b/src/menu.rs index 947bc69..baa7ea0 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -40,8 +40,17 @@ fn read(input: &mut Input, timeout: &Duration) -> Result { uefi::boot::create_event_ex(EventType::TIMER, Tpl::CALLBACK, None, None, None) .context("unable to create timer event")? }; + // The timeout is in increments of 100 nanoseconds. - let trigger = TimerTrigger::Relative(timeout.as_nanos() as u64 / 100); + let timeout_hundred_nanos = timeout.as_nanos() / 100; + + // Check if the timeout is too large to fit into an u64. + if timeout_hundred_nanos > u64::MAX as u128 { + bail!("timeout duration overflow"); + } + + // Set a timer to trigger after the specified duration. + let trigger = TimerTrigger::Relative(timeout_hundred_nanos as u64); uefi::boot::set_timer(&timer_event, trigger).context("unable to set timeout timer")?; let mut events = vec![timer_event, key_event];