Skip to content

Commit 255382a

Browse files
committed
Write to des place in write_byte_helper
1 parent 2734395 commit 255382a

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
@@ -621,8 +621,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
621621
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
622622
return Ok(());
623623
};
624-
let res = write_byte_helper(offset, fd, bytes, communicate, this)?;
625-
this.write_scalar(res, dest)?;
624+
write_byte_helper(offset, fd, bytes, communicate, dest, this)?;
626625
Ok(())
627626
}
628627

@@ -665,20 +664,25 @@ fn write_byte_helper<'tcx>(
665664
fd: FileDescriptionRef,
666665
bytes: Vec<u8>,
667666
communicate: bool,
667+
dest: &MPlaceTy<'tcx>,
668668
ecx: &mut MiriInterpCx<'tcx>,
669-
) -> InterpResult<'tcx, Scalar> {
669+
) -> InterpResult<'tcx> {
670670
let result = match offset {
671671
None => fd.write(&fd, communicate, &bytes, ecx),
672672
Some(offset) => {
673673
let Ok(offset) = u64::try_from(offset) else {
674674
let einval = ecx.eval_libc("EINVAL");
675675
ecx.set_last_error(einval)?;
676-
return Ok(Scalar::from_target_isize(-1, ecx));
676+
let res = Scalar::from_target_isize(-1, ecx);
677+
ecx.write_scalar(res, dest)?;
678+
return Ok(());
677679
};
678680
fd.pwrite(communicate, &bytes, offset, ecx)
679681
}
680682
};
683+
// Write the result to the dest place.
681684
let result = result?.map(|c| i64::try_from(c).unwrap());
682-
let res = ecx.try_unwrap_io_result(result)?;
683-
Ok(Scalar::from_target_isize(res, ecx))
685+
let res = Scalar::from_target_isize(ecx.try_unwrap_io_result(result)?, ecx);
686+
ecx.write_scalar(res, dest)?;
687+
return Ok(());
684688
}

0 commit comments

Comments
 (0)