-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect error message for offset_from() on pointers to two different allocations. #4143
Comments
For some reason, printing the pointer before calling fn main() {
let x: &u8 = &1_u8;
println!("{:p}", x);
unsafe {
(x as *const u8).offset_from(&2_u8);
}
}
Note the "expected a pointer to the end of 51524 bytes of memory" in the error. I think this indicates that something has gone very wrong inside miri. |
The error is confusing but not fundamentally incorrect: the nicest way to check "are these two pointers in the same allocation" that also accounts for edge cases like identical pointers is to check "is the memory range between them dereferenceable from both pointers". That's what Miri is doing, and it's where the "4 bytes of memory" expectation comes from: the two pointers happen to be 4 bytes apart in that case. I still think that this is the nicest implementation strategy, but we should probably find a way to make the error less confusing. |
Rollup merge of rust-lang#136438 - RalfJung:offset_from_ub_errors, r=oli-obk miri: improve error when offset_from preconditions are violated Fixes rust-lang/miri#4143
miri: improve error when offset_from preconditions are violated Fixes #4143
I ran the following code with Miri:
I expected Miri to sensibly report some UB, but instead I got the following:
The error message doesn't make any sense. I don't know where Miri got the "4 bytes of memory" expectation from. So I think the error is incorrect.
Reproducible on the playground with rust version
1.86.0-nightly (2025-01-20 f3d1d47fd84dfcf7f513)
The text was updated successfully, but these errors were encountered: