-
Notifications
You must be signed in to change notification settings - Fork 876
Closed
Labels
Description
Lines 303 to 306 in 83d0ac4
if next_idx == 0 { | |
self.inner | |
.push_back(unsafe { mem::MaybeUninit::uninit().assume_init() }); | |
} |
This is explicitly noted in the MaybeUninit docs as undefined behavior (std::mem:;unintialized
was deprecated for a reason!). The correct solution is to store [MaybeUninit<T>; BLOCK_SIZE]
in the type, and to only call assume_init()
on individual items that are known to be initialized.
(also unrelated: the current implementation of ArrayList<T>
is not safe for T that have destructors due to its use of indexed assignment instead of ptr::write
. It should have a T: Copy
bound to reflect this)