GetFirefly / firefly

An alternative BEAM implementation, designed for WebAssembly
Apache License 2.0
3.61k stars 104 forks source link

offset_of #691

Closed RalfJung closed 2 years ago

RalfJung commented 3 years ago

The offset_of macro at https://github.com/lumen/lumen/blob/521fda4d040a53ad53ed88174650c60959bdbcc8/liblumen_core/src/util.rs#L9 is not quite correct... it avoids creating dangling pointers, but it does create a reference to the uninitialized struct via &*u.as_ptr(). To avoid this, ptr::addr_of! should be used instead of &.

The memoffset crate provides a version of this macro that avoids UB (on older versions of rustc, this is not always possible, so it falls back to the 'least incorrect' version when needed).

bcardarella commented 3 years ago

@bitwalker is this being changed in your pending PR or should we track this?

bitwalker commented 2 years ago

Closing as completed, since that crate and macro have been removed in the rewrite