Skip to content

Commit 4baef71

Browse files
committed
Fix maximum isize value for target
1 parent edd0157 commit 4baef71

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/shims/fs.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
173173
let count = this
174174
.read_scalar(count_op)?
175175
.to_machine_usize(&*this.tcx)?
176-
.min(1 << (ptr_size - 1))
176+
.min((1 << (ptr_size - 1)) - 1) // max value of target `isize`
177177
.min(isize::max_value() as u64);
178178
// Reading zero bytes should not change `buf`.
179179
if count == 0 {
@@ -193,8 +193,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
193193
let result = handle
194194
.file
195195
.read(&mut bytes)
196-
// `File::read` never returns a value larger than `i64::max_value()`, so this
197-
// unwrap cannot fail.
196+
// `File::read` never returns a value larger than `count`, so this cannot fail.
198197
.map(|c| i64::try_from(c).unwrap());
199198

200199
match result {
@@ -230,7 +229,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
230229
let count = this
231230
.read_scalar(count_op)?
232231
.to_machine_usize(&*this.tcx)?
233-
.min(1 << (ptr_size - 1))
232+
.min((1 << (ptr_size - 1)) - 1) // max value of target `isize`
234233
.min(isize::max_value() as u64);
235234
// Writing zero bytes should not change `buf`.
236235
if count == 0 {

0 commit comments

Comments
 (0)