add missing null ptr check in alloc example
This commit is contained in:
parent
b3f4c31199
commit
080a53a953
1 changed files with 4 additions and 1 deletions
|
@ -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::<u16>();
|
||||
/// let ptr = alloc(layout);
|
||||
/// if ptr.is_null() {
|
||||
/// handle_alloc_error(layout);
|
||||
/// }
|
||||
///
|
||||
/// *(ptr as *mut u16) = 42;
|
||||
/// assert_eq!(*(ptr as *mut u16), 42);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue