Skip to content

Commit

Permalink
Auto merge of #3578 - RalfJung:realloc, r=RalfJung
Browse files Browse the repository at this point in the history
avoid code duplication between realloc and malloc
  • Loading branch information
bors committed May 6, 2024
2 parents 4ddbd30 + 3818794 commit d0e9e5a
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/shims/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let new_align = this.min_align(new_size, kind);
if this.ptr_is_null(old_ptr)? {
// Here we must behave like `malloc`.
if new_size == 0 {
Ok(Pointer::null())
} else {
let new_ptr =
this.allocate_ptr(Size::from_bytes(new_size), new_align, kind.into())?;
Ok(new_ptr.into())
}
self.malloc(new_size, /*zero_init*/ false, kind)
} else {
if new_size == 0 {
// C, in their infinite wisdom, made this UB.
Expand Down

0 comments on commit d0e9e5a

Please sign in to comment.