-
Notifications
You must be signed in to change notification settings - Fork 146
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
Dropping SmallVecN is unsound #4
Comments
CC @pcwalton |
I think this used to be sound when Rust had both drop flags and zeroing-on-drop, but that changed in rust-lang/rust#23535. We could probably go back to the old behavior by initializing with rust-lang/rfcs#197 is also relevant. |
The replacement for zeroed is |
Using |
For example, this segfaults:
SmallVec4<T>
contains a[T; 4]
field directly, which is initialized innew
withstd::mem::zeroed()
. When the vector is dropped, the destructor forT
is run for each of the 4T
s, even if there isn’t actually aT
there (i.e. if the vector’s length is less than 4 by the time it is dropped).https://github.com/bluss/arrayvec works around this issue by having (simplified):
with a destructor that resets to
Dropped
before the recursive destructors are run implicitly.In
SmallVecN
, the second variant could instead contain the pointer and capacity for a spilled vector (reset to null/zero during destruction).The text was updated successfully, but these errors were encountered: