Skip to content

Commit e2ed272

Browse files
author
Ellen Arteca
committed
proper check for size of allocation being aligned
1 parent f7a991b commit e2ed272

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+3
-1
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
449449
// `force_int_for_alignment_check` can only be true if `OFFSET_IS_ADDR` is true.
450450
// TODO do a proper check here
451451
// now, addr().bytes() will not give the size of the allocation, it'll be the address
452-
// check_offset_align(ptr.addr().bytes(), align)?;
452+
// instead, get the allocation corresponding to this `AllocId` and get the size from it
453+
let alloc = self.get_alloc_raw(alloc_id)?;
454+
check_offset_align(alloc.size().bytes(), align)?;
453455
} else {
454456
// Check allocation alignment and offset alignment.
455457
if alloc_align.bytes() < align.bytes() {

0 commit comments

Comments
 (0)