-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 on libc::strlen(some_cstr.as_ptr())
#7145
Labels
Comments
Inspired by rust-lang/rust#84589 (comment) |
What about for |
@mgacek8 That seems reasonable, yes. The lint should apply to either |
I'll give it a shot. |
This was referenced May 18, 2021
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
May 19, 2021
…_type, r=davidtwco Add diagnostic item to `CStr` Required for clippy issue: rust-lang/rust-clippy#7145
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
May 19, 2021
…_type, r=davidtwco Add diagnostic item to `CStr` Required for clippy issue: rust-lang/rust-clippy#7145
RalfJung
added a commit
to RalfJung/rust
that referenced
this issue
May 19, 2021
…_type, r=davidtwco Add diagnostic item to `CStr` Required for clippy issue: rust-lang/rust-clippy#7145
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
What it does
This lint would flag the use of
libc::strlen
on aCString
orCStr
value, and suggest callingto_bytes().len()
instead.Categories (optional)
clippy::complexity
What is the advantage of the recommended code over the original code
This avoids calling an unsafe
libc
function. Currently, it also avoids calculating the length; in the future, this may become equivalent to callingstrlen
at runtime, but it'll still avoid the need for an unsafelibc
call.Drawbacks
None.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: