rust-lang/rust-clippy

Lint to warn about str::as_ptr() usage in ffi call

Open

#1.236 geöffnet am 19. Sept. 2016

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (1.391 Forks)batch import
A-lintL-correctnessT-middlegood first issue

Repository-Metriken

Stars
 (10.406 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 22h) (113 gemergte PRs in 30 T)

Beschreibung

Hello. It would be nice to have a warning when using str::as_ptr() in a ffi call instead of using CStr.

For instance, in the following code:

unsafe { printf("Hello".as_ptr() as *const _) };

should give a warning and propose something like:

let cstring = CString::new("Hello".as_bytes()).unwrap();
unsafe { printf(cstring.as_ptr()) };

Thanks to add this lint.

Contributor Guide