diff options
| author | Josh Stone <jistone@redhat.com> | 2024-11-11 16:30:37 -0800 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2024-11-11 16:30:37 -0800 |
| commit | 2ddb91acd1867bbaad3986fdef63d4953a0fb37a (patch) | |
| tree | f86421b2e682923a85c90db24054ccc860d5651a /library/alloc/src | |
| parent | 81eef2d362a6f03db6f8928f82d94298d31eb81b (diff) | |
| download | rust-2ddb91acd1867bbaad3986fdef63d4953a0fb37a.tar.gz rust-2ddb91acd1867bbaad3986fdef63d4953a0fb37a.zip | |
Check for null in the `alloc_zeroed` example
We should demonstrate good behavior, just like #99198 did for `alloc`.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/alloc.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index a91659b6de5..98402a46201 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -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); /// |
