-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
I tried this code:
fn some_function(data: *const u8) {}
fn main() {
let string = "hello";
some_function(CString::new(string).unwrap().as_ptr());
}
I expected no clippy complains about this one.
Instead, clippy gave "that pointer will be invalid outside this expression". Yes, "that pointer will be invalid outside this expression", but I only need it valid inside this expression, so this is a false positive.
Meta
- Clippy 0.0.212 (2020-07-23 0820e54)
- Reproducible on Playground as of 2020-07-24
Backtrace
error: you are getting the inner pointer of a temporary `CString`
--> src/main.rs:7:19
|
7 | some_function(CString::new(string).unwrap().as_ptr());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(clippy::temporary_cstring_as_ptr)]` on by default
= note: that pointer will be invalid outside this expression
help: assign the `CString` to a variable to extend its lifetime
--> src/main.rs:7:19
|
7 | some_function(CString::new(string).unwrap().as_ptr());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have