Closed
Description
This code violates pointer provenance rules:
fn insert_fit(&mut self, key: K, val: V) -> *mut V {
debug_assert!(self.node.len() < CAPACITY);
unsafe {
slice_insert(self.node.keys_mut(), self.idx, key);
slice_insert(self.node.vals_mut(), self.idx, val);
self.node.as_leaf_mut().len += 1;
self.node.val_mut_at(self.idx)
}
}
Specifically, self.node.keys_mut()
returns a slice covering the previously existing elements of this node, but it is used to also access the new element one-past-the-end of the previous slice.
Either slice_insert
needs to be passed a slice covering all the memory it needs to access (of type &mut [MaybeUninit<_>]
), or else it needs to be passed a raw pointer (that may access the entire buffer) and a length. But keys_mut
/vals_mut
can only be used to access elements that already exist, not to initialize new elements.
Cc @ssomers