Skip to content

Commit 7567e5b

Browse files
committed
Remove write_byte_helper
1 parent c8f2d0f commit 7567e5b

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
@@ -621,8 +621,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
621621
this.write_scalar(Scalar::from_target_isize(res, this), dest)?;
622622
return Ok(());
623623
};
624-
self.write_byte_helper(offset, fd, bytes, communicate, dest)?;
625-
Ok(())
624+
625+
let result = match offset {
626+
None => fd.write(&fd, communicate, &bytes, this),
627+
Some(offset) => {
628+
let Ok(offset) = u64::try_from(offset) else {
629+
let einval = this.eval_libc("EINVAL");
630+
this.set_last_error(einval)?;
631+
return Ok(Scalar::from_target_isize(-1, this));
632+
};
633+
fd.pwrite(communicate, &bytes, offset, this)
634+
}
635+
};
636+
637+
let result = result?.map(|c| i64::try_from(c).unwrap());
638+
Ok(Scalar::from_target_isize(this.try_unwrap_io_result(result)?, this))
626639
}
627640

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

0 commit comments

Comments
 (0)