-
Notifications
You must be signed in to change notification settings - Fork 271
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Transmuting from a reference to a mutable reference is insta-UB: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8da5074ba78a22ba108e198273c547ba
error: Undefined Behavior: writing to alloc1 which is read-only
--> src/main.rs:5:17
|
5 | let _ = core::mem::transmute::<&[u8; 10], &mut [libc::c_char; 10]>(b"\0\0\0\0\0\0\0\0\0\0");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc1 which is read-only
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at src/main.rs:5:17: 5:100
C2rust currently does such transmutes for code like char mode2[10] = "";
where it produces let mut mode2: [libc::c_char; 10] = *core::mem::transmute::<&[u8; 10], &mut [libc::c_char; 10]>(b"\0\0\0\0\0\0\0\0\0\0");
even though let mut mode2: [libc::c_char; 10] = [0; 10];
works just fine.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working