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
Uplift clippy::invalid_null_ptr_usage
lint
#119220
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
b25c44c
to
7308419
Compare
This comment has been minimized.
This comment has been minimized.
7308419
to
05aabc1
Compare
I think @saethlin has also found plenty of code that hits this in the wild, so this seems like a good lint. |
You're probably referring to PyO3/pyo3#2687 and servo/font-kit#197 I don't think either of these would be detected by the lint, but I agree that this is a reasonable lint target. |
I'll flag this as |
☔ The latest upstream changes (presumably #120991) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR aims at uplifting the
clippy::invalid_null_ptr_usage
lint into rustc, this is similar to theclippy::invalid_utf8_in_unchecked
uplift a few months ago, in the sense that those two lints lint on invalid parameter(s), here a null pointer where it is unexpected and UB to pass one.For context: GitHub Search reveals that just for
slice::from_raw_parts{_mut}
~20 invalid usages withptr::null
and an additional 4 invalid usages with0 as *const ...
-ish casts.invalid_null_ptr_usages
(deny-by-default)
The
invalid_null_ptr_usages
lint checks for invalid usage of null pointers.Example
Produces:
Explanation
Calling methods who's safety invariants requires non-null pointer with a null pointer is undefined behavior.
The lint use a list of functions to know which functions and arguments to checks, this could be improved in the future with a rustc attribute, or maybe even with a
#[diagnostic]
attribute.This PR also includes some small refactoring to avoid some ambiguities in naming, those can be done in another PR is desired.
@rustbot label: +I-lang-nominated
r? compiler