Skip to content

Commit 8ae118d

Browse files
committed
Move the maxevents.try_into().unwrap() after value check
1 parent c0e799d commit 8ae118d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/tools/miri/src/shims/unix/linux/epoll.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -403,18 +403,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
403403

404404
let epfd = this.read_scalar(epfd)?.to_i32()?;
405405
let maxevents = this.read_scalar(maxevents)?.to_i32()?;
406-
let event = this.deref_pointer_as(
407-
events_op,
408-
this.libc_array_ty_layout("epoll_event", maxevents.try_into().unwrap()),
409-
)?;
410406
let timeout = this.read_scalar(timeout)?.to_i32()?;
411-
412407
if epfd <= 0 || maxevents <= 0 {
413408
let einval = this.eval_libc("EINVAL");
414409
this.set_last_error(einval)?;
415410
return Ok(Scalar::from_i32(-1));
416411
}
417412

413+
// This needs to come after the maxevents value check, or else maxevents.try_into().unwrap()
414+
// will fail.
415+
let event = this.deref_pointer_as(
416+
events_op,
417+
this.libc_array_ty_layout("epoll_event", maxevents.try_into().unwrap()),
418+
)?;
419+
418420
// FIXME: Implement blocking support
419421
if timeout != 0 {
420422
throw_unsup_format!("epoll_wait: timeout value can only be 0");

src/tools/miri/tests/pass-dep/libc/libc-epoll.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
test_epoll_ctl_del();
2020
test_pointer();
2121
test_two_same_fd_in_same_epoll_instance();
22-
test_epoll_wait_less_maxevent_zero();
22+
test_epoll_wait_maxevent_zero();
2323
}
2424

2525
// Using `as` cast since `EPOLLET` wraps around
@@ -530,8 +530,7 @@ fn test_no_notification_for_unregister_flag() {
530530
check_epoll_wait::<8>(epfd, &[(expected_event, expected_value)]);
531531
}
532532

533-
534-
fn test_epoll_wait_less_maxevent_zero() {
533+
fn test_epoll_wait_maxevent_zero() {
535534
// Create an epoll instance.
536535
let epfd = unsafe { libc::epoll_create1(0) };
537536
assert_ne!(epfd, -1);

0 commit comments

Comments
 (0)