diff options
| author | Elichai Turkel <elichai.turkel@gmail.com> | 2020-08-26 17:02:24 +0300 |
|---|---|---|
| committer | Elichai Turkel <elichai.turkel@gmail.com> | 2020-08-26 17:02:24 +0300 |
| commit | 0cca5978a454fe7087d0182a8bfa1372a6aae320 (patch) | |
| tree | a3d2e74caaef693684b6428c3e3d8b36a3746f6e | |
| parent | ffd59bf9c62125813abae8ca52f0ac3a67459e8f (diff) | |
| download | rust-0cca5978a454fe7087d0182a8bfa1372a6aae320.tar.gz rust-0cca5978a454fe7087d0182a8bfa1372a6aae320.zip | |
Fix potential UB in align_offset docs
| -rw-r--r-- | library/core/src/ptr/const_ptr.rs | 2 | ||||
| -rw-r--r-- | library/core/src/ptr/mut_ptr.rs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index fc70dec16f6..d09cdb44e08 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -836,7 +836,7 @@ impl<T: ?Sized> *const T { /// # use std::mem::align_of; /// # unsafe { /// let x = [5u8, 6u8, 7u8, 8u8, 9u8]; - /// let ptr = &x[n] as *const u8; + /// let ptr = x.as_ptr().add(n) as *const u8; /// let offset = ptr.align_offset(align_of::<u16>()); /// if offset < x.len() - n - 1 { /// let u16_ptr = ptr.add(offset) as *const u16; diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 2d25f21e55c..537aa20bf1d 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1094,7 +1094,7 @@ impl<T: ?Sized> *mut T { /// # use std::mem::align_of; /// # unsafe { /// let x = [5u8, 6u8, 7u8, 8u8, 9u8]; - /// let ptr = &x[n] as *const u8; + /// let ptr = x.as_ptr().add(n) as *const u8; /// let offset = ptr.align_offset(align_of::<u16>()); /// if offset < x.len() - n - 1 { /// let u16_ptr = ptr.add(offset) as *const u16; |
