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
This is probably rather niche, but it seems like a low-hanging fruit.
Here is a code example:
let x:*constu8 = {let a = 0u8;&a
};unsafe{let x = x.add(0);}
Error message
error: Undefined Behavior: pointer to alloc1494 was dereferenced after this allocation got freed
Except… nothing was dereferenced. The pointer's value didn't even change.
From what I gathered by reading the documentation, .add creates immediate UB if it outputs a pointer whose dereferencing would be illegal, which is exactly the case here; indeed, although the value doesn't change, it's UB according to the documentation. But it's not exactly correct to claim that it was dereferenced when it wasn't.
The text was updated successfully, but these errors were encountered:
Yeah, the code that checks dereferencability and offset-inbounds is shared but clearly we should differentiate this for the error message. We do this successfully (I think) for the message saying that the pointer is no in-bounds, but use-after-free is checked earlier. Probably PointerUseAfterFree should also take a CheckInAllocMsg.
RalfJung
changed the title
Imprecise error message when creating dangling pointer with add
Imprecise error message when doing inbounds pointer arithmetic on pointer to freed allocation
Apr 28, 2023
This is probably rather niche, but it seems like a low-hanging fruit.
Here is a code example:
Error message
Except… nothing was dereferenced. The pointer's value didn't even change.
From what I gathered by reading the documentation,
.add
creates immediate UB if it outputs a pointer whose dereferencing would be illegal, which is exactly the case here; indeed, although the value doesn't change, it's UB according to the documentation. But it's not exactly correct to claim that it was dereferenced when it wasn't.The text was updated successfully, but these errors were encountered: