pub static TEMPORARY_CSTRING_AS_PTR: &Lint
Expand description

The temporary_cstring_as_ptr lint detects getting the inner pointer of a temporary CString.

Example

let c_str = CString::new("foo").unwrap().as_ptr();

{{produces}}

Explanation

The inner pointer of a CString lives only as long as the CString it points to. Getting the inner pointer of a temporary CString allows the CString to be dropped at the end of the statement, as it is not being referenced as far as the typesystem is concerned. This means outside of the statement the pointer will point to freed memory, which causes undefined behavior if the pointer is later dereferenced.