Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
orlp opened this issue Oct 20, 2018 · 3 comments
Closed
Labels

Comments

@orlp
Copy link

orlp commented Oct 20, 2018

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.

@bluss bluss added the bug label Oct 27, 2018
@bluss
Copy link
Owner

bluss commented Oct 27, 2018

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

@bluss
Copy link
Owner

bluss commented Nov 25, 2018

See also #97 and related issues and prs

@bluss
Copy link
Owner

bluss commented Jul 10, 2019

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

@bluss bluss closed this as completed Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants