Skip to content

Commit

Permalink
Fix potential UB in align_offset docs
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Aug 26, 2020
1 parent ffd59bf commit 0cca597
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/core/src/ptr/const_ptr.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mut_ptr.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 0cca597

Please sign in to comment.