From 7a34c31cb21156e8f223ca51ae3757f327a1208a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 12 Jul 2022 20:43:04 -0400 Subject: [PATCH] add missing null ptr check in alloc example --- alloc/src/alloc.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/alloc/src/alloc.rs b/alloc/src/alloc.rs index 649aeb089..efdc86bf5 100644 --- a/alloc/src/alloc.rs +++ b/alloc/src/alloc.rs @@ -70,11 +70,14 @@ pub use std::alloc::Global; /// # Examples /// /// ``` -/// use std::alloc::{alloc, dealloc, Layout}; +/// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout}; /// /// unsafe { /// let layout = Layout::new::(); /// let ptr = alloc(layout); +/// if ptr.is_null() { +/// handle_alloc_error(layout); +/// } /// /// *(ptr as *mut u16) = 42; /// assert_eq!(*(ptr as *mut u16), 42);