firefly icon indicating copy to clipboard operation
firefly copied to clipboard

offset_of

Open RalfJung opened this issue 4 years ago • 1 comments

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).

RalfJung avatar Apr 03 '21 17:04 RalfJung

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

bcardarella avatar Apr 07 '21 15:04 bcardarella

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

bitwalker avatar Aug 25 '22 06:08 bitwalker