Address review comments
This commit is contained in:
parent
6ba127d3f0
commit
cb8b9012db
5 changed files with 8 additions and 9 deletions
|
@ -109,7 +109,6 @@ use crate::sys;
|
||||||
/// documentation of `CString` before use, as improper ownership management
|
/// documentation of `CString` before use, as improper ownership management
|
||||||
/// of `CString` instances can lead to invalid memory accesses, memory leaks,
|
/// of `CString` instances can lead to invalid memory accesses, memory leaks,
|
||||||
/// and other memory errors.
|
/// and other memory errors.
|
||||||
|
|
||||||
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
|
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "cstring_type")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// ignore-tidy-linelength
|
|
||||||
#![deny(temporary_cstring_as_ptr)]
|
#![deny(temporary_cstring_as_ptr)]
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
@ -6,5 +5,6 @@ use std::ffi::CString;
|
||||||
fn some_function(data: *const i8) {}
|
fn some_function(data: *const i8) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
some_function(CString::new("").unwrap().as_ptr()); //~ ERROR getting the inner pointer of a temporary `CString`
|
some_function(CString::new("").unwrap().as_ptr());
|
||||||
|
//~^ ERROR getting the inner pointer of a temporary `CString`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: getting the inner pointer of a temporary `CString`
|
error: getting the inner pointer of a temporary `CString`
|
||||||
--> $DIR/lint-temporary-cstring-as-param.rs:9:45
|
--> $DIR/lint-temporary-cstring-as-param.rs:8:45
|
||||||
|
|
|
|
||||||
LL | some_function(CString::new("").unwrap().as_ptr());
|
LL | some_function(CString::new("").unwrap().as_ptr());
|
||||||
| ------------------------- ^^^^^^ this pointer will be invalid
|
| ------------------------- ^^^^^^ this pointer will be invalid
|
||||||
|
@ -7,7 +7,7 @@ LL | some_function(CString::new("").unwrap().as_ptr());
|
||||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/lint-temporary-cstring-as-param.rs:2:9
|
--> $DIR/lint-temporary-cstring-as-param.rs:1:9
|
||||||
|
|
|
|
||||||
LL | #![deny(temporary_cstring_as_ptr)]
|
LL | #![deny(temporary_cstring_as_ptr)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// ignore-tidy-linelength
|
|
||||||
// this program is not technically incorrect, but is an obscure enough style to be worth linting
|
// this program is not technically incorrect, but is an obscure enough style to be worth linting
|
||||||
#![deny(temporary_cstring_as_ptr)]
|
#![deny(temporary_cstring_as_ptr)]
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s = CString::new("some text").unwrap().as_ptr(); //~ ERROR getting the inner pointer of a temporary `CString`
|
let s = CString::new("some text").unwrap().as_ptr();
|
||||||
|
//~^ ERROR getting the inner pointer of a temporary `CString`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: getting the inner pointer of a temporary `CString`
|
error: getting the inner pointer of a temporary `CString`
|
||||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:8:48
|
--> $DIR/lint-temporary-cstring-as-ptr.rs:7:48
|
||||||
|
|
|
|
||||||
LL | let s = CString::new("some text").unwrap().as_ptr();
|
LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||||
| ---------------------------------- ^^^^^^ this pointer will be invalid
|
| ---------------------------------- ^^^^^^ this pointer will be invalid
|
||||||
|
@ -7,7 +7,7 @@ LL | let s = CString::new("some text").unwrap().as_ptr();
|
||||||
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/lint-temporary-cstring-as-ptr.rs:3:9
|
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
|
||||||
|
|
|
|
||||||
LL | #![deny(temporary_cstring_as_ptr)]
|
LL | #![deny(temporary_cstring_as_ptr)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue