-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Hi. We are using your library at rust-analyzer, specifically rowan red-green syntax tree crate.
We have stumbled with invalid free() (here is the link to that issue).
I just took a quick look into the places where we use unsafe code and stepped into your crate. I am not entirely sure whether this comes from here, otherwise, I would've created a bug report.
I just have some questions about these lines of code here:
Lines 111 to 121 in 1da8b7a
| unsafe fn fatten_const(ptr: ErasedPtr) -> NonNull<Self> { | |
| let len = ptr::read(Self::len(ptr).as_ptr()); | |
| let slice = make_slice(ptr.cast::<SliceItem>().as_ptr(), len); | |
| NonNull::new_unchecked(slice as *const Self as *mut Self) | |
| } | |
| unsafe fn fatten_mut(ptr: ErasedPtr) -> NonNull<Self> { | |
| let len = ptr::read(Self::len(ptr).as_ptr()); | |
| let slice = make_slice_mut(ptr.cast::<SliceItem>().as_ptr(), len); | |
| NonNull::new_unchecked(slice as *mut Self) | |
| } |
First of alI, I am not a pro in unsafe counterpart of Rust, please just correct me if I am wrong.
My questions are:
- What is the intent of having two functions that have the same signature but operate on
*const _and*mut _pointers in their body respectively? I've heard this has something to do with pointer provenance, though I am not entirely sure in this context. - It seems that we are casting ptr to
usizeand toSliceItemat the first and the second lines of these functions (which is like we are doing type punning), but I don't see why we would do that. Could you please elaborate?
llebout
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested