Skip to content

Commit 3914be9

Browse files
committed
Further move the dest place to read_byte_helper
1 parent 19b85a6 commit 3914be9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/shims/unix/fd.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
581581
fd.pread(communicate, &mut bytes, offset, this)
582582
}
583583
};
584-
let res = read_byte_helper(buf, bytes, result, this)?;
585-
this.write_scalar(res, dest)?;
584+
read_byte_helper(buf, bytes, result, dest, this)?;
586585
Ok(())
587586
}
588587

@@ -624,8 +623,9 @@ fn read_byte_helper<'tcx>(
624623
buf: Pointer,
625624
bytes: Vec<u8>,
626625
result: InterpResult<'tcx, io::Result<usize>>,
626+
dest: &MPlaceTy<'tcx>,
627627
ecx: &mut MiriInterpCx<'tcx>,
628-
) -> InterpResult<'tcx, Scalar> {
628+
) -> InterpResult<'tcx> {
629629
// `File::read` never returns a value larger than `count`, so this cannot fail.
630630
match result?.map(|c| i64::try_from(c).unwrap()) {
631631
// try to pass this the write_ptr inside write
@@ -638,11 +638,13 @@ fn read_byte_helper<'tcx>(
638638
buf,
639639
bytes[..usize::try_from(read_bytes).unwrap()].iter().copied(),
640640
)?;
641-
Ok(Scalar::from_target_isize(read_bytes, ecx))
641+
ecx.write_scalar(Scalar::from_target_isize(read_bytes, ecx), dest)?;
642+
return Ok(());
642643
}
643644
Err(e) => {
644645
ecx.set_last_error_from_io_error(e)?;
645-
Ok(Scalar::from_target_isize(-1, ecx))
646+
ecx.write_scalar(Scalar::from_target_isize(-1, ecx), dest)?;
647+
return Ok(());
646648
}
647649
}
648650
}

0 commit comments

Comments
 (0)