Skip to content

Commit d6795a7

Browse files
committed
precise getrandom return type and align_offset arithmetic
1 parent b7fec6b commit d6795a7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/shims/foreign_items/posix/linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ fn getrandom<'tcx>(
140140
let _flags = this.read_scalar(args[2])?.to_i32()?;
141141

142142
this.gen_random(ptr, len)?;
143-
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
143+
this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;
144144
Ok(())
145145
}

src/shims/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7575
let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
7676

7777
// Default: no result.
78-
let mut result = this.truncate(u128::MAX, dest.layout);
78+
let mut result = this.usize_max();
7979
if let Ok(ptr) = this.force_ptr(ptr_scalar) {
8080
// Only do anything if we can identify the allocation this goes to.
8181
let cur_align =
@@ -84,15 +84,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8484
// If the allocation alignment is at least the required alignment we use the
8585
// libcore implementation.
8686
// FIXME: is this correct in case of truncation?
87-
result = u128::try_from(
87+
result = u64::try_from(
8888
(this.force_bits(ptr_scalar, this.pointer_size())? as *const i8)
8989
.align_offset(usize::try_from(req_align).unwrap())
9090
).unwrap();
9191
}
9292
}
9393

9494
// Return result, and jump to caller.
95-
this.write_scalar(Scalar::from_uint(result, this.pointer_size()), dest)?;
95+
this.write_scalar(Scalar::from_machine_usize(result, this), dest)?;
9696
this.go_to_block(ret);
9797
Ok(())
9898
}

0 commit comments

Comments
 (0)