Skip to content

MaybeUninit in TakeOwnCell #3

Closed as not planned
Closed as not planned
@noamtashma

Description

@noamtashma

Since TakeOwnCell doesn't put its data inside a MaybeUninit, this means that that data always has to satisfy the validity requirements of that type.

But since that value can be moved away, it might not.

For example, if we create a TakeOwnCell<Box<u32>>, take the box, and then deallocate the box, the data inside the empty TakeOwnCell would hold a pointer to freed memory, which makes it invalid.

I tried to confirm this with miri, but my miri tests passed. I'm not sure why - Maybe I missed something, or maybe this causes the violation to not be found because it's not marked dereferencable because of the UnsafeCell (But I also tried with an older version of miri and it also passed).

However If I didn't misunderstand anything this is still UB.

This can be fixed by putting the data inside a MaybeUninit, since moved away values are basically the same as uninitialized values.

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