Skip to content

lint on libc::strlen(some_cstr.as_ptr()) #7145

Closed
@joshtriplett

Description

@joshtriplett

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

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions