Skip to content

Commit

Permalink
Rollup merge of rust-lang#132929 - cuviper:check-alloc_zeroed, r=tgro…
Browse files Browse the repository at this point in the history
…ss35

Check for null in the `alloc_zeroed` example

We should demonstrate good behavior, just like rust-lang#99198 did for `alloc`.
  • Loading branch information
matthiaskrgr authored Nov 12, 2024
2 parents 0555bb2 + 2ddb91a commit 119b939
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
/// # Examples
///
/// ```
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
/// use std::alloc::{alloc_zeroed, dealloc, handle_alloc_error, Layout};
///
/// unsafe {
/// let layout = Layout::new::<u16>();
/// let ptr = alloc_zeroed(layout);
/// if ptr.is_null() {
/// handle_alloc_error(layout);
/// }
///
/// assert_eq!(*(ptr as *mut u16), 0);
///
Expand Down

0 comments on commit 119b939

Please sign in to comment.