Skip to content

Commit ac8e665

Browse files
committed
Write to des place in write_byte_helper
1 parent 750c959 commit ac8e665

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/shims/unix/fd.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
622622
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
623623
return Ok(());
624624
};
625-
let res = write_byte_helper(offset, fd, bytes, communicate, this)?;
626-
this.write_scalar(res, dest)?;
625+
write_byte_helper(offset, fd, bytes, communicate, dest, this)?;
627626
Ok(())
628627
}
629628

@@ -666,20 +665,25 @@ fn write_byte_helper<'tcx>(
666665
fd: FileDescriptionRef,
667666
bytes: Vec<u8>,
668667
communicate: bool,
668+
dest: &MPlaceTy<'tcx>,
669669
ecx: &mut MiriInterpCx<'tcx>,
670-
) -> InterpResult<'tcx, Scalar> {
670+
) -> InterpResult<'tcx> {
671671
let result = match offset {
672672
None => fd.write(&fd, communicate, &bytes, ecx),
673673
Some(offset) => {
674674
let Ok(offset) = u64::try_from(offset) else {
675675
let einval = ecx.eval_libc("EINVAL");
676676
ecx.set_last_error(einval)?;
677-
return Ok(Scalar::from_target_isize(-1, ecx));
677+
let res = Scalar::from_target_isize(-1, ecx);
678+
ecx.write_scalar(res, dest)?;
679+
return Ok(());
678680
};
679681
fd.pwrite(communicate, &bytes, offset, ecx)
680682
}
681683
};
684+
// Write the result to the dest place.
682685
let result = result?.map(|c| i64::try_from(c).unwrap());
683-
let res = ecx.try_unwrap_io_result(result)?;
684-
Ok(Scalar::from_target_isize(res, ecx))
686+
let res = Scalar::from_target_isize(ecx.try_unwrap_io_result(result)?, ecx);
687+
ecx.write_scalar(res, dest)?;
688+
return Ok(());
685689
}

0 commit comments

Comments
 (0)