Closed
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()