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

[lint idea] dangerous transmutes #546

Open
durka opened this issue Jan 13, 2016 · 6 comments
Open

[lint idea] dangerous transmutes #546

durka opened this issue Jan 13, 2016 · 6 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types

Comments

@durka
Copy link
Contributor

durka commented Jan 13, 2016

Along the lines of useless_transmute, it seems plausible to warn on transmute::<X, Y>(x) where X and Y aren't both primitive types or marked #[repr(C)], since as @ubsan keeps reminding us this is likely to cause UB.

@strega-nil
Copy link

@durka heh :)

The only valid transmutes of a repr(Rust) struct that I know of are in std::repr, so it should(?) be fairly simple to special case those.

@Ryman
Copy link

Ryman commented Jan 13, 2016

I would love to see something like this, it's very easy to forget about and have seen it come up a number of times.

@Manishearth Manishearth added good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Jan 28, 2016
@durka
Copy link
Contributor Author

durka commented Jan 29, 2016

@ubsan I expect running clippy on libstd would trigger more lints than that :)

@oli-obk
Copy link
Contributor

oli-obk commented May 12, 2016

also casting a #[repr(C)] struct with padding to anything where the padding becomes accessible is UB

@durka
Copy link
Contributor Author

durka commented May 12, 2016

Does clippy have access to ask rustc whether a struct has any padding, or
would the logic have to be duplicated?

On Thu, May 12, 2016 at 11:15 AM, Oliver Schneider <notifications@github.com

wrote:

also casting a #[repr(C)] struct with padding to anything where the
padding becomes accessible is UB


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/Manishearth/rust-clippy/issues/546#issuecomment-218789297

@oli-obk
Copy link
Contributor

oli-obk commented May 12, 2016

clippy can ask rustc, at least miri can do it (since a few weeks ago), so clippy should be able to do it, too.

bors added a commit that referenced this issue Feb 6, 2022
Add lint `transmute_undefined_repr`

Partially implements #3999 and #546

This doesn't consider `enum`s at all right now as those are going to be a pain to deal with. This also allows `#[repr(Rust)]` structs with only one non-zero sized fields. I think those are technically undefined when transmuted.

changelog: Add lint `transmute_undefined_repr`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

6 participants