@@ -583,7 +583,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
583583 fd. pread ( communicate, & mut bytes, offset, this)
584584 }
585585 } ;
586- let res = write_byte_helper ( buf, bytes, result, this) ?;
586+ let res = read_byte_helper ( buf, bytes, result, this) ?;
587587 this. write_scalar ( res, dest) ?;
588588 Ok ( ( ) )
589589 }
@@ -617,27 +617,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
617617 this. write_scalar ( Scalar :: from_target_isize ( res, this) , dest) ?;
618618 return Ok ( ( ) ) ;
619619 } ;
620-
621- let result = match offset {
622- None => fd. write ( & fd, communicate, & bytes, this) ,
623- Some ( offset) => {
624- let Ok ( offset) = u64:: try_from ( offset) else {
625- let einval = this. eval_libc ( "EINVAL" ) ;
626- this. set_last_error ( einval) ?;
627- this. write_scalar ( Scalar :: from_target_isize ( -1 , this) , dest) ?;
628- return Ok ( ( ) ) ;
629- } ;
630- fd. pwrite ( communicate, & bytes, offset, this)
631- }
632- } ;
633-
634- let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
635- let res = this. try_unwrap_io_result ( result) ?;
636- this. write_scalar ( Scalar :: from_target_isize ( res, this) , dest) ?;
620+ let res = write_byte_helper ( offset, fd, bytes, communicate, this) ?;
621+ this. write_scalar ( res, dest) ?;
637622 Ok ( ( ) )
638623 }
639624}
640- fn write_byte_helper < ' tcx > (
625+ fn read_byte_helper < ' tcx > (
641626 buf : Pointer ,
642627 bytes : Vec < u8 > ,
643628 result : InterpResult < ' tcx , io:: Result < usize > > ,
@@ -665,3 +650,26 @@ fn write_byte_helper<'tcx>(
665650 }
666651 }
667652}
653+
654+ fn write_byte_helper < ' tcx > (
655+ offset : Option < i128 > ,
656+ fd : FileDescriptionRef ,
657+ bytes : Vec < u8 > ,
658+ communicate : bool ,
659+ ecx : & mut MiriInterpCx < ' tcx > ,
660+ ) -> InterpResult < ' tcx , Scalar > {
661+ let result = match offset {
662+ None => fd. write ( & fd, communicate, & bytes, ecx) ,
663+ Some ( offset) => {
664+ let Ok ( offset) = u64:: try_from ( offset) else {
665+ let einval = ecx. eval_libc ( "EINVAL" ) ;
666+ ecx. set_last_error ( einval) ?;
667+ return Ok ( Scalar :: from_target_isize ( -1 , ecx) ) ;
668+ } ;
669+ fd. pwrite ( communicate, & bytes, offset, ecx)
670+ }
671+ } ;
672+ let result = result?. map ( |c| i64:: try_from ( c) . unwrap ( ) ) ;
673+ let res = ecx. try_unwrap_io_result ( result) ?;
674+ Ok ( Scalar :: from_target_isize ( res, ecx) )
675+ }
0 commit comments