You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Transmuting from a reference to a mutable reference is insta-UB: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8da5074ba78a22ba108e198273c547ba
C2rust currently does such transmutes for code like
char mode2[10] = "";
where it produceslet 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 thoughlet mut mode2: [libc::c_char; 10] = [0; 10];
works just fine.The text was updated successfully, but these errors were encountered: