Skip to content

ArrayVec is undefined behavior when storing types with invalid bit patterns #105

Closed
@orlp

Description

@orlp

Initially in an ArrayVec the memory is uninitialized: https://github.com/bluss/arrayvec/blob/master/src/lib.rs#L80.

This simply is UB in Rust for any types with invalid bit patterns (most notably references). Just creating an uninitialized value with these bit patterns is UB.

Even perfectly fine code that never actually reads or uses the uninitialized memory still has undefined behavior. I ran into this myself: https://stackoverflow.com/questions/52348277/vector-is-empty-after-cloning-struct-with-uninitialized-member.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions