rust-lang/rust-clippy

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

Open

#1236 aperta il 19 set 2016

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Rust (1391 fork)batch import
A-lintL-correctnessT-middlegood first issue

Metriche repository

Star
 (10.406 star)
Metriche merge PR
 (Merge medio 19g 22h) (113 PR mergiate in 30 g)

Descrizione

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.

Guida contributor