You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code in arena-rs is unsound, because there is no guarantee, that zero-initialized data is a properly initialized T and dereferencing non-properly initialized data is an undefined behavior:
unsafe{*ptr = value;// ...}
The *ptr = value line should be replaced with std::ptr::write(ptr, value).
There is no guarantee that T object is properly aligned and thus there is an another undefined behavior because only a pointer to a properly aligned object can be dereferenced without undefined behavior.
Arena should use std::mem::align_of to obtain information about T alignment, and insert appropriate padding before T.
The text was updated successfully, but these errors were encountered:
A1-Triard
changed the title
There is unsound unsafe code in arean-rs
There is unsound unsafe code in arena-rs
Aug 14, 2020
The following code in arena-rs is unsound, because there is no guarantee, that zero-initialized data is a properly initialized
T
and dereferencing non-properly initialized data is an undefined behavior:The
*ptr = value
line should be replaced withstd::ptr::write(ptr, value)
.There is no guarantee that
T
object is properly aligned and thus there is an another undefined behavior because only a pointer to a properly aligned object can be dereferenced without undefined behavior.Arena
should usestd::mem::align_of
to obtain information aboutT
alignment, and insert appropriate padding beforeT
.The text was updated successfully, but these errors were encountered: