Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPossible UB from use of uninitialized `[&T; N]` #126
Comments
This comment has been minimized.
This comment has been minimized.
|
See also rust-lang/rust#54542. |
This comment has been minimized.
This comment has been minimized.
|
I can't make the test fail, but I think we have a problem hiding in here, as long as an optional smallvec of references is the same size as the plain type: |
bluss
referenced this issue
Dec 3, 2018
Closed
Implement a stop-gap “MaybeUninit” using ManuallyDrop #97
This comment has been minimized.
This comment has been minimized.
|
SmallVec contains an enum, so I think the enum layout optimization is using spare bits from that enum's tag to store the Option discriminant. If this is true then we're not seeing incorrect behavior in practice yet. |
nox
referenced this issue
Feb 1, 2019
Open
Using "mem::unitialized()" can lead to "Attempted to instantiate uninhabited type" #139
This comment has been minimized.
This comment has been minimized.
|
I recently looked into the use of |
mbrubeck commentedSep 25, 2018
•
edited
Creating an array with
mem::uninitializedmay be UB if the array's elements contain non-null types (like&T) or uninhabited types (like!) or other types that have invalid values.This can result in undefined behavior even if you never read the elements directly while they are uninitialized. For example, this program prints "true" if optimizations are enabled, when built with current rustc:
SmallVecisn't eligible for null pointer optimization, so it isn't affected by this. However, it's possible that a future Rust compiler could add other optimizations that break if SmallVec usesmem::uninitializedto create arrays of such types.The ideal solution is to switch from
uninitializedto the newMaybeUninitunion (rust-lang/rfcs#1892) when it becomes stable.