Skip to content

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

Closed

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.

Activity

  1. bluss commented on Oct 27, 2018

    @bluss
    Owner

    Thanks, this is something that has clarified a lot in recent versions of Rust, and we should be able to use MaybeUninitialized soon.

  2. bluss commented on Nov 25, 2018

    @bluss
    Owner

    See also #97 and related issues and prs

  3. bluss commented on Jul 10, 2019

    @bluss
    Owner

    Closed by #127 with the caveat, that Rust 1.36 or later is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions