Skip to content

Commit 5d04e07

Browse files
committed
Remove write_byte_helper
1 parent 1f4ecff commit 5d04e07

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/shims/unix/fd.rs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
622622
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
623623
return Ok(());
624624
};
625-
self.write_byte_helper(offset, fd, bytes, communicate, dest)?;
626-
Ok(())
625+
626+
let result = match offset {
627+
None => fd.write(&fd, communicate, &bytes, this),
628+
Some(offset) => {
629+
let Ok(offset) = u64::try_from(offset) else {
630+
let einval = this.eval_libc("EINVAL");
631+
this.set_last_error(einval)?;
632+
return Ok(Scalar::from_target_isize(-1, this));
633+
};
634+
fd.pwrite(communicate, &bytes, offset, this)
635+
}
636+
};
637+
638+
let result = result?.map(|c| i64::try_from(c).unwrap());
639+
Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
627640
}
628641

629642
/// This function write bytes to the user supplied buffer and write the total number of bytes
@@ -658,34 +671,4 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
658671
}
659672
}
660673
}
661-
662-
fn write_byte_helper(
663-
&mut self,
664-
offset: Option<i128>,
665-
fd: FileDescriptionRef,
666-
bytes: Vec<u8>,
667-
communicate: bool,
668-
dest: &MPlaceTy<'tcx>,
669-
) -> InterpResult<'tcx> {
670-
let this = self.eval_context_mut();
671-
672-
let result = match offset {
673-
None => fd.write(&fd, communicate, &bytes, this),
674-
Some(offset) => {
675-
let Ok(offset) = u64::try_from(offset) else {
676-
let einval = this.eval_libc("EINVAL");
677-
this.set_last_error(einval)?;
678-
let res = Scalar::from_target_isize(-1, this);
679-
this.write_scalar(res, dest)?;
680-
return Ok(());
681-
};
682-
fd.pwrite(communicate, &bytes, offset, this)
683-
}
684-
};
685-
// Write the result to the dest place.
686-
let result = result?.map(|c| i64::try_from(c).unwrap());
687-
let res = Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this);
688-
this.write_scalar(res, dest)?;
689-
return Ok(());
690-
}
691674
}

0 commit comments

Comments
 (0)