Skip to content

Commit 9a37af8

Browse files
saethlinBurntSushi
authored andcommitted
safety: conform to stacked borrows
When using 'get_unchecked' twice where one is a mutable borrow, it ends up creating UB under the "stacked borrows" model. Which isn't adopted yet. Still, it seems likely that it will? So we fix it by deriving both pointers to 'ptr::copy' from the same 'get_unchecked_mut' call. Closes #121
1 parent bc10172 commit 9a37af8

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/ext_slice.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,11 +3063,8 @@ pub trait ByteSlice: Sealed {
30633063
// Finally, we are only dealing with u8 data, which is Copy, which
30643064
// means we can copy without worrying about ownership/destructors.
30653065
unsafe {
3066-
ptr::copy(
3067-
self.as_bytes().get_unchecked(src_start),
3068-
self.as_bytes_mut().get_unchecked_mut(dest),
3069-
count,
3070-
);
3066+
let ptr = self.as_bytes_mut().as_mut_ptr();
3067+
ptr::copy(ptr.add(src_start), ptr.add(dest), count);
30713068
}
30723069
}
30733070
}

0 commit comments

Comments
 (0)