Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use raw pointers to avoid aliasing violation in split_at_mut
Fixes #27357
  • Loading branch information
bluss committed Jul 28, 2015
1 parent 1b28ffa commit 73d4330
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libcore/slice.rs
Expand Up @@ -288,11 +288,12 @@ impl<T> SliceExt for [T] {

#[inline]
fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
let len = self.len();
let ptr = self.as_mut_ptr();
assert!(mid <= len);
unsafe {
let self2: &mut [T] = mem::transmute_copy(&self);

(ops::IndexMut::index_mut(self, ops::RangeTo { end: mid } ),
ops::IndexMut::index_mut(self2, ops::RangeFrom { start: mid } ))
(from_raw_parts_mut(ptr, mid),
from_raw_parts_mut(ptr.offset(mid as isize), len - mid))
}
}

Expand Down

0 comments on commit 73d4330

Please sign in to comment.