Skip to content

Commit

Permalink
Check for null in the alloc_zeroed example
Browse files Browse the repository at this point in the history
We should demonstrate good behavior, just like rust-lang#99198 did for `alloc`.
  • Loading branch information
cuviper committed Nov 12, 2024
1 parent b541c5a commit 67c3c9f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion 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 67c3c9f

Please sign in to comment.