diff options
| author | Ralf Jung <post@ralfj.de> | 2022-07-12 20:43:04 -0400 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-07-14 11:37:22 -0400 |
| commit | 080a53a9533de30c614f37d006985c2f26fd30e7 (patch) | |
| tree | eef4e0749cb3d5d2397fc7f4a956394d8b9a68b8 /library/alloc/src/alloc.rs | |
| parent | b3f4c3119957aa0a250cab08ab586b7a9a680ef1 (diff) | |
| download | rust-080a53a9533de30c614f37d006985c2f26fd30e7.tar.gz rust-080a53a9533de30c614f37d006985c2f26fd30e7.zip | |
add missing null ptr check in alloc example
Diffstat (limited to 'library/alloc/src/alloc.rs')
| -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 649aeb0890d..efdc86bf57a 100644 --- a/library/alloc/src/alloc.rs +++ b/library/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::<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); |
