mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-17 02:26:46 +00:00
Check the length of timers before access
This commit is contained in:
parent
2102107be1
commit
c38907374a
@ -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`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user