Skip to content

Commit f187a5c

Browse files
committed
Fix a warning in upstream code on Rust nightly.
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.
1 parent 417d238 commit f187a5c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/uucore/src/lib/features/entries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ macro_rules! f {
321321
} else {
322322
// SAFETY: We're holding PW_LOCK.
323323
unsafe {
324-
let data = $fnam(CString::new(k).unwrap().as_ptr());
324+
let cstring = CString::new(k).unwrap();
325+
let data = $fnam(cstring.as_ptr());
325326
if !data.is_null() {
326327
Ok($st::from_raw(ptr::read(data as *const _)))
327328
} else {

0 commit comments

Comments
 (0)