-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
This lint would flag the use of libc::strlen
on a CString
or CStr
value, and suggest calling to_bytes().len()
instead.
Categories (optional)
- Kind:
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 calling strlen
at runtime, but it'll still avoid the need for an unsafe libc
call.
Drawbacks
None.
Example
libc::strlen(name.as_ptr())
Could be written as:
name.to_bytes().len()
In-line, mgacek8 and jplatteAlphaHot
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy