Skip to content

Convert a pointer to u64, then convert the u64 back to a pointer,crash in android ndk #145523

@ChenJiawei94

Description

@ChenJiawei94

I tried this code:

<code>
pub struct Node{}
let node = Rc::new(Node{});
let ptr = Rc::into_raw();
let ptr_u64 : u64 = unsafe{std::mem::transmute(ptr)};
let ptr2 : *const Node = unsafe{std::mem::transmute(ptr_u64)};
unsafe{(*ptr2).some_function()};//crash here.

I expected to see this happen: normal run.

Instead, this happened:crash in android ndk.

Meta

rustc --version --verbose:

<version>1.89
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-gubCategory: the reverse of a compiler bug is generally UB

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions