diff options
| author | Ralf Jung <post@ralfj.de> | 2024-09-22 16:37:00 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-09-22 16:50:37 +0200 |
| commit | 5dee646aea06ec06d35c0fbd13489e83996be0b5 (patch) | |
| tree | d26ddfa7498272ee5f055591f83d4cec78e892be /src | |
| parent | fb1193078da1c3d8f41d744d8979e4ea76a8d120 (diff) | |
| download | rust-5dee646aea06ec06d35c0fbd13489e83996be0b5.tar.gz rust-5dee646aea06ec06d35c0fbd13489e83996be0b5.zip | |
read, write: move cast-to-usize logic up and deduplicate it
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/shims/unix/fd.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/tools/miri/src/shims/unix/fd.rs b/src/tools/miri/src/shims/unix/fd.rs index c0f179ccdce..1ab6f921cfb 100644 --- a/src/tools/miri/src/shims/unix/fd.rs +++ b/src/tools/miri/src/shims/unix/fd.rs @@ -579,6 +579,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let count = count .min(u64::try_from(this.target_isize_max()).unwrap()) .min(u64::try_from(isize::MAX).unwrap()); + let count = usize::try_from(count).unwrap(); // now it fits in a `usize` let communicate = this.machine.communicate(); // We temporarily dup the FD to be able to retain mutable access to `this`. @@ -595,7 +596,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // `usize::MAX` because it is bounded by the host's `isize`. match offset { - None => fd.read(&fd, communicate, buf, usize::try_from(count).unwrap(), dest, this)?, + None => fd.read(&fd, communicate, buf, count, dest, this)?, Some(offset) => { let Ok(offset) = u64::try_from(offset) else { let einval = this.eval_libc("EINVAL"); @@ -603,7 +604,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.write_int(-1, dest)?; return Ok(()); }; - fd.pread(communicate, offset, buf, usize::try_from(count).unwrap(), dest, this)? + fd.pread(communicate, offset, buf, count, dest, this)? } }; Ok(()) @@ -629,6 +630,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let count = count .min(u64::try_from(this.target_isize_max()).unwrap()) .min(u64::try_from(isize::MAX).unwrap()); + let count = usize::try_from(count).unwrap(); // now it fits in a `usize` let communicate = this.machine.communicate(); // We temporarily dup the FD to be able to retain mutable access to `this`. @@ -639,7 +641,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { }; match offset { - None => fd.write(&fd, communicate, buf, usize::try_from(count).unwrap(), dest, this)?, + None => fd.write(&fd, communicate, buf, count, dest, this)?, Some(offset) => { let Ok(offset) = u64::try_from(offset) else { let einval = this.eval_libc("EINVAL"); @@ -647,7 +649,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { this.write_int(-1, dest)?; return Ok(()); }; - fd.pwrite(communicate, buf, usize::try_from(count).unwrap(), offset, dest, this)? + fd.pwrite(communicate, buf, count, offset, dest, this)? } }; Ok(()) |
