Skip to content

Commit d304960

Browse files
committed
Fix undefined behavior in Hole::move_to()
1 parent 9fb9cd7 commit d304960

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/binary_heap.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ impl<'a, T> Hole<'a, T> {
428428
unsafe fn move_to(&mut self, index: usize) {
429429
debug_assert!(index != self.pos);
430430
debug_assert!(index < self.data.len());
431-
let index_ptr: *const _ = self.data.get_unchecked(index);
432-
let hole_ptr = self.data.get_unchecked_mut(self.pos);
431+
let ptr = self.data.as_mut_ptr();
432+
let index_ptr: *const _ = ptr.add(index);
433+
let hole_ptr = ptr.add(self.pos);
433434
ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1);
434435
self.pos = index;
435436
}

0 commit comments

Comments
 (0)