diff options
author | 2022-04-28 17:26:02 -0400 | |
---|---|---|
committer | 2022-04-28 17:26:02 -0400 | |
commit | d3049604244bab3cef9cf62565ce8a5bc1e0ab75 (patch) | |
tree | 8ee56a6d664da36461f5735f7a5f3e06abb17898 /src/binary_heap.rs | |
parent | 9fb9cd70451bd8c4e6ccf51ca3c77b8cb033fc27 (diff) | |
download | heapless-d3049604244bab3cef9cf62565ce8a5bc1e0ab75.tar.gz heapless-d3049604244bab3cef9cf62565ce8a5bc1e0ab75.tar.zst heapless-d3049604244bab3cef9cf62565ce8a5bc1e0ab75.zip |
Fix undefined behavior in `Hole::move_to()`
Diffstat (limited to '')
-rw-r--r-- | src/binary_heap.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/binary_heap.rs b/src/binary_heap.rs index f82f3d7d..dc9ea590 100644 --- a/src/binary_heap.rs +++ b/src/binary_heap.rs @@ -428,8 +428,9 @@ impl<'a, T> Hole<'a, T> { unsafe fn move_to(&mut self, index: usize) { debug_assert!(index != self.pos); debug_assert!(index < self.data.len()); - let index_ptr: *const _ = self.data.get_unchecked(index); - let hole_ptr = self.data.get_unchecked_mut(self.pos); + let ptr = self.data.as_mut_ptr(); + let index_ptr: *const _ = ptr.add(index); + let hole_ptr = ptr.add(self.pos); ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1); self.pos = index; } |