@@ -579,6 +579,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
579
579
let count = count
580
580
. min ( u64:: try_from ( this. target_isize_max ( ) ) . unwrap ( ) )
581
581
. min ( u64:: try_from ( isize:: MAX ) . unwrap ( ) ) ;
582
+ let count = usize:: try_from ( count) . unwrap ( ) ; // now it fits in a `usize`
582
583
let communicate = this. machine . communicate ( ) ;
583
584
584
585
// We temporarily dup the FD to be able to retain mutable access to `this`.
@@ -595,15 +596,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
595
596
// `usize::MAX` because it is bounded by the host's `isize`.
596
597
597
598
match offset {
598
- None => fd. read ( & fd, communicate, buf, usize :: try_from ( count) . unwrap ( ) , dest, this) ?,
599
+ None => fd. read ( & fd, communicate, buf, count, dest, this) ?,
599
600
Some ( offset) => {
600
601
let Ok ( offset) = u64:: try_from ( offset) else {
601
602
let einval = this. eval_libc ( "EINVAL" ) ;
602
603
this. set_last_error ( einval) ?;
603
604
this. write_int ( -1 , dest) ?;
604
605
return Ok ( ( ) ) ;
605
606
} ;
606
- fd. pread ( communicate, offset, buf, usize :: try_from ( count) . unwrap ( ) , dest, this) ?
607
+ fd. pread ( communicate, offset, buf, count, dest, this) ?
607
608
}
608
609
} ;
609
610
Ok ( ( ) )
@@ -629,6 +630,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
629
630
let count = count
630
631
. min ( u64:: try_from ( this. target_isize_max ( ) ) . unwrap ( ) )
631
632
. min ( u64:: try_from ( isize:: MAX ) . unwrap ( ) ) ;
633
+ let count = usize:: try_from ( count) . unwrap ( ) ; // now it fits in a `usize`
632
634
let communicate = this. machine . communicate ( ) ;
633
635
634
636
// We temporarily dup the FD to be able to retain mutable access to `this`.
@@ -639,15 +641,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
639
641
} ;
640
642
641
643
match offset {
642
- None => fd. write ( & fd, communicate, buf, usize :: try_from ( count) . unwrap ( ) , dest, this) ?,
644
+ None => fd. write ( & fd, communicate, buf, count, dest, this) ?,
643
645
Some ( offset) => {
644
646
let Ok ( offset) = u64:: try_from ( offset) else {
645
647
let einval = this. eval_libc ( "EINVAL" ) ;
646
648
this. set_last_error ( einval) ?;
647
649
this. write_int ( -1 , dest) ?;
648
650
return Ok ( ( ) ) ;
649
651
} ;
650
- fd. pwrite ( communicate, buf, usize :: try_from ( count) . unwrap ( ) , offset, dest, this) ?
652
+ fd. pwrite ( communicate, buf, count, offset, dest, this) ?
651
653
}
652
654
} ;
653
655
Ok ( ( ) )
0 commit comments