Skip to content

Commit 575aa90

Browse files
committed
Skip the usize to u64 conversion
1 parent d7ee32d commit 575aa90

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/shims/unix/fd.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,19 +653,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
653653
dest: &MPlaceTy<'tcx>,
654654
) -> InterpResult<'tcx> {
655655
let this = self.eval_context_mut();
656-
// `File::read` never returns a value larger than `count`, so this cannot fail.
657-
match result.map(|c| i64::try_from(c).unwrap()) {
658-
// try to pass this the write_ptr inside write
659-
// Pass the pointer inside the write function.
656+
match result {
660657
Ok(read_bytes) => {
661658
// If reading to `bytes` did not fail, we write those bytes to the buffer.
662659
// Crucially, if fewer than `bytes.len()` bytes were read, only write
663660
// that much into the output buffer!
664-
this.write_bytes_ptr(
665-
buf,
666-
bytes[..usize::try_from(read_bytes).unwrap()].iter().copied(),
667-
)?;
668-
this.write_int(read_bytes, dest)?;
661+
this.write_bytes_ptr(buf, bytes[..read_bytes].iter().copied())?;
662+
// The actual read size is always lesser than `count` so this cannot fail.
663+
this.write_int(u64::try_from(read_bytes).unwrap(), dest)?;
669664
return Ok(());
670665
}
671666
Err(e) => {

0 commit comments

Comments
 (0)