#Undefined Behavior with custom allocator and Box

11 messages · Page 1 of 1 (latest)

amber bobcat
#

MIRI is telling me my code has undefined behavior based on Stacked Borrows rules, and I am quite out of my depth. Is this code wrong? And if so, how do i fix it?

#

i'm using the paste crate to create unique identifiers but other than that, no external crates

haughty breach
#

let ptr = unsafe { NonNull::new_unchecked(self.stack.as_ptr().add(aligned) as *mut _) }; isn’t the problem here that you’re casting a *const T to *mut?

amber bobcat
#

oh dear you are absolutely correct, that fixed it

#

i knew that returned a const pointer, but i missed it because NonNull::as_ptr returns a mut pointer

#

thanks!

amber bobcat
#

hello hello, one bug down, and another to take its place