Skip to content

Commit

Permalink
Fix potential crash on large constant ZST slice
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Sep 26, 2023
1 parent ca18301 commit cb55ce1
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ pub(crate) fn codegen_const_value<'tcx>(
ConstValue::Slice { data, meta } => {
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data);
let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx);
// FIXME: the `try_from` here can actually fail, e.g. for very long ZST slices.
let len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(meta).unwrap());
let len = fx.bcx.ins().iconst(fx.pointer_type, meta as i64);
CValue::by_val_pair(ptr, len, layout)
}
}
Expand Down

0 comments on commit cb55ce1

Please sign in to comment.