Skip to content

Commit 97d693a

Browse files
committed
assert sanity in memory
1 parent b06a8db commit 97d693a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/librustc_mir/interpret/memory.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
258258
}
259259
Scalar::Bits { bits, size } => {
260260
assert_eq!(size as u64, self.pointer_size().bytes());
261-
// FIXME: what on earth does this line do? docs or fix needed!
262-
let v = ((bits as u128) % (1 << self.pointer_size().bytes())) as u64;
263-
if v == 0 {
261+
assert!(bits < (1u128 << self.pointer_size().bits()));
262+
if bits == 0 {
264263
return err!(InvalidNullPointerUsage);
265264
}
266-
// the base address if the "integer allocation" is 0 and hence always aligned
267-
(v, required_align)
265+
// the "base address" is 0 and hence always aligned
266+
(bits as u64, required_align)
268267
}
269268
};
270269
// Check alignment

0 commit comments

Comments
 (0)