Skip to content

Commit 122549f

Browse files
committed
Simplify read logic
1 parent d7967f6 commit 122549f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/shims/fs.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
177177
// We want to read at most `count` bytes
178178
let mut bytes = vec![0; count as usize];
179179
let result = handle.file.read(&mut bytes).map(|c| c as i64);
180-
let written_count = this.try_unwrap_io_result(result)?;
181-
// `try_unwrap_io_result` returns Ok(`-1`) if `result` is an error. There is no other
182-
// way of returning `-1` because the `Ok` variant of `result` contains the number of
183-
// written bytes, which is a possitive value.
184-
if written_count != -1 {
185-
// If reading to `bytes` did not fail, we write those bytes to the buffer.
180+
// If reading to `bytes` did not fail, we write those bytes to the buffer.
181+
if result.is_ok() {
186182
this.memory.write_bytes(buf, bytes)?;
187183
}
188-
Ok(written_count)
184+
this.try_unwrap_io_result(result)
189185
} else {
190186
this.handle_not_found()
191187
}

0 commit comments

Comments
 (0)