Skip to content

MaybeUninit::uninit().assume_init() is undefined behavior #536

@ExpHP

Description

@ExpHP

pyo3/src/gil.rs

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions