Skip to content

move temporary_cstring_as_ptr from clippy to rustc #34111

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

Closed
oli-obk opened this issue Jun 6, 2016 · 5 comments
Closed

move temporary_cstring_as_ptr from clippy to rustc #34111

oli-obk opened this issue Jun 6, 2016 · 5 comments

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jun 6, 2016

Quoting the docs of the lint:

What it does: This lint checks for getting the inner pointer of a temporary CString.
Why is this bad? The inner pointer of a CString is only valid as long as the CString is alive.

@akademik someone found in a recent discussion that there are hundreds of .unwrap().as_ptr() calls to be found on github (not all of them UB, but many).

I believe this amount of accidental UB is reason enough to add a "new" lint to rustc that prevents misusing this specific easy-to-misuse method.

@aka-demik
Copy link

We are different aka-demik's ;)

@steveklabnik
Copy link
Member

New lints pretty much require RFCs these days.

@durka
Copy link
Contributor

durka commented Jun 6, 2016

Or we could just deprecate the method (with a message warning of the potential for misuse) and provide fn with_ptr<F: FnOnce(*const c_char)>(&self, f: F) { f(self.as_ptr()); } instead. Example.

@durka
Copy link
Contributor

durka commented Jun 6, 2016

rust-lang/rfcs#1642 submitted.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 6, 2016

Let's continue further discussion on the rfc

@oli-obk oli-obk closed this as completed Jun 6, 2016
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

4 participants