Check the length of timers before access

This commit is contained in:
Marsman1996 2024-08-21 13:51:43 +08:00 committed by Tate, Hongliang Tian
parent 2102107be1
commit c38907374a

View File

@ -187,7 +187,12 @@ impl PosixTimerManager {
/// Finds a POSIX timer by the input `timer_id`. /// Finds a POSIX timer by the input `timer_id`.
pub fn find_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> { pub fn find_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
self.posix_timers.lock()[timer_id].clone() let timers = self.posix_timers.lock();
if timer_id < timers.len() {
timers[timer_id].clone()
} else {
None
}
} }
/// Removes the POSIX timer with the ID `timer_id`. /// Removes the POSIX timer with the ID `timer_id`.