Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a warning in upstream code on Rust nightly. #4781

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

sunfishcode
Copy link
Contributor

Rust nightly recently started issuing the following warning when compiling coreutils:

warning: getting the inner pointer of a temporary `CString`
   --> src/uucore/src/lib/features/entries.rs:324:67
    |
324 |                         let data = $fnam(CString::new(k).unwrap().as_ptr());
    |                                          ------------------------ ^^^^^^ this pointer will be invalid
    |                                          |
    |                                          this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
...
340 | f!(getpwnam, getpwuid, uid_t, Passwd);
    | ------------------------------------- in this macro invocation
    |
    = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
    = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
    = note: `#[warn(temporary_cstring_as_ptr)]` on by default
    = note: this warning originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)

There doesn't seem to be an actual problem in this case, as the pointer is only used within the statement.

Rust nightly recently [started] issuing the following warning when
compiling coreutils:

[started]: rust-lang/rust#109944

```
warning: getting the inner pointer of a temporary `CString`
   --> src/uucore/src/lib/features/entries.rs:324:67
    |
324 |                         let data = $fnam(CString::new(k).unwrap().as_ptr());
    |                                          ------------------------ ^^^^^^ this pointer will be invalid
    |                                          |
    |                                          this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
...
340 | f!(getpwnam, getpwuid, uid_t, Passwd);
    | ------------------------------------- in this macro invocation
    |
    = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
    = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
    = note: `#[warn(temporary_cstring_as_ptr)]` on by default
    = note: this warning originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
```

There doesn't seem to be an actual problem in this case, as the pointer is
only used within the statement.
@sylvestre
Copy link
Contributor

nice to see you here @sunfishcode :)
thanks!

@sylvestre sylvestre merged commit d3fc670 into uutils:main Apr 25, 2023
@sunfishcode sunfishcode deleted the sunfishcode/fix-warning branch April 25, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants