hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.2K
active users

Ben Kimock

Since nightly-2023-04-01, this Rust code can panic:

unsafe {*(1 as *const i32)}

because rustc now inserts a check that raw pointers are aligned before dereferencing them.

github.com/rust-lang/rust/pull

This check is only inserted when debug assertions are enabled. If you have any notable experience with this, drop me a line!

GitHubInsert alignment checks for pointer dereferences when debug assertions are enabled by saethlin · Pull Request #98112 · rust-lang/rustBy saethlin

Just based on the PR itself, so far this has caught a bug in the Rust test suite and three (3) bugs in real code.

Defaults are good. Checks are good.

Now 6 bugs in real code

Also possibly one bug in the implementation 🙃

I am working on another check similar to this that detects using bytes as a type which would be invalid because the type's niche is occupied by the bytes.

You can read the prototype code here: github.com/rust-lang/rust/pull

GitHubCheck for occupied niches by saethlin · Pull Request #104862 · rust-lang/rustBy saethlin

For example, this check detects transmuting 0 to a NonZero type, or 4 to a bool.

It may also detect using raw pointers to write an invalid discriminant to an enum, but only if you try to access the bytes that you wrote as the enum type. This is the "validity on typed copy" rule that Miri implements. In a real sense, you can Fuck Around, so long as you don't tell the type system what you're doing.

@saethlin I'll be sure to only access my raw pointers via inline asm from now on!

@Lokathor @saethlin or use `unaligned_read`/`unaligned_write` (or turn this check off if you really wanna UB)

@streganil @Lokathor That doesn't defeat the check! It makes your code well-defined :D