Skip to content

The way ptr_XX and inner_set_XX are implemented is UB #10

Description

@Voultapher

For example

pub unsafe fn ptr_0(&mut self) -> *mut String {
    let inner = self.inner.as_mut_ptr();
    &raw mut (*inner).a
}

A reference in Rust gurantees that the memory is initialized. You need to use addr_of_mut to correctly model this.


Somewhat unrleated but I thought I'd mention it.

let ptr =
    &self as *const OrangeBuilder<AUnset, FieldB> as
        *const OrangeBuilder<ASet, FieldB>;
::core::mem::forget(self);
unsafe { ptr.read() }

That looks a lot like transmute. Is there a specific reason not to use transmute here? Also this is UB too, the docs for mem::forget

Any resources the value manages, such as heap memory or a file handle, will linger forever in an unreachable state. However, it does not guarantee that pointers to this memory will remain valid.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions