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
Allocating a type with alignment bigger than 4 bytes sometimes gets allocated on address which is not a multiple of that alignment, causing accesses to fail debug_assert! in slice::from_raw_parts_*
structSomething{x:f64,y:f32}fnmain() -> anyhow::Result<()>{
esp_idf_sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
log::info!("align_of::<Something>(): {}", std::mem::align_of::<Something>());
log::info!("size_of::<Something>(): {}", std::mem::size_of::<Something>());loop{let r = rand::random::<usize>() % 100;letmut v = Vec::with_capacity(r);
log::info!("pointer: 0x{:x}", v.as_ptr()asusize);
log::info!("v.as_ptr() % std::mem::align_of::<Something>() == {}", v.as_ptr()asusize % std::mem::align_of::<Something>());unsafe{ v.set_len(r);};
log::info!("fill");for x in&mut v {*x = Something{x:10f64,y:20f32};}
log::info!("filled");
std::thread::sleep(std::time::Duration::from_millis(100));}Ok(())}
Note that the alignment of Something is 8, and sometimes the pointer is not a multiple of 8, causing a panic in for x in &mut v { in debug builds.
Allocating a type with alignment bigger than 4 bytes sometimes gets allocated on address which is not a multiple of that alignment, causing accesses to fail
debug_assert!
inslice::from_raw_parts_*
Note that the alignment of
Something
is 8, and sometimes the pointer is not a multiple of 8, causing a panic infor x in &mut v {
in debug builds.Happens on ESP32 with Rust STD library, using https://github.com/ivmarkov/rust-esp32-std-demo
The text was updated successfully, but these errors were encountered: