Skip to content

Commit

Permalink
Address potential future UB by only using raw pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Sep 27, 2024
1 parent 1ce75c1 commit 6b28835
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,11 +1330,12 @@ impl<T, A: Allocator> RawTable<T, A> {
) -> [Option<NonNull<T>>; N] {
// TODO use `MaybeUninit::uninit_array` here instead once that's stable.
let mut outs: MaybeUninit<[Option<NonNull<T>>; N]> = MaybeUninit::uninit();
let outs_ptr = outs.as_mut_ptr();
// TODO use `*mut [T; N]::as_mut_ptr` here instead once that's stable.
let outs_ptr = outs.as_mut_ptr() as *mut Option<NonNull<T>>;

for (i, &hash) in hashes.iter().enumerate() {
let cur = self.find(hash, |k| eq(i, k)).map(|cur| cur.as_non_null());
*(*outs_ptr).get_unchecked_mut(i) = cur;
outs_ptr.add(i).write(cur);
}

outs.assume_init()
Expand Down

0 comments on commit 6b28835

Please sign in to comment.