Skip to content
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

Comparing pointers into different allocations #724

Closed
kpp opened this issue May 7, 2019 · 2 comments
Closed

Comparing pointers into different allocations #724

kpp opened this issue May 7, 2019 · 2 comments

Comments

@kpp
Copy link

kpp commented May 7, 2019

MRE:

use std::ffi::CStr;

fn main() {
    let cstr = CStr::from_bytes_with_nul(b"hello\0");
    assert!(cstr.is_ok());
    let ptr = cstr.unwrap().as_ptr();
    dbg!(ptr); // << here
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=9a0295250c20f63f16a5895438502d8a

Error:

[src/main.rs:7] ptr = error[E0080]: Miri evaluation error: attempted to do invalid arithmetic on pointers that would leak base addresses, e.g., comparing pointers into different allocations
   --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cmp.rs:978:52
    |
978 |                 fn ge(&self, other: &$t) -> bool { (*self) >= (*other) }
    |                                                    ^^^^^^^^^^^^^^^^^^^ Miri evaluation error: attempted to do invalid arithmetic on pointers that would leak base addresses, e.g., comparing pointers into different allocations
    |

Discovered in rust-lang/rust#60606

@oli-obk
Copy link
Contributor

oli-obk commented May 7, 2019

This is expected. Even just dbg!(&1 as *const i32); by itself will fail in miri.

The issue tracking a solution to this is #224

@oli-obk oli-obk closed this as completed May 7, 2019
@kpp
Copy link
Author

kpp commented May 7, 2019

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants