Fix potential UB in align_offset docs
This commit is contained in:
parent
ffd59bf9c6
commit
0cca5978a4
2 changed files with 2 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue