From cbb6eb9203fd68af39c23ffcd11982aff017443b Mon Sep 17 00:00:00 2001 From: teutat3s <10206665+teutat3s@users.noreply.github.com> Date: Sun, 10 Apr 2022 23:59:20 +0200 Subject: [PATCH] Fix build lifetime issue on freebsd, netbsd, illumos and solaris, too warning: getting the inner pointer of a temporary `CString` --> src/bpf.rs:82:57 | 82 | CString::new(&b"/dev/bpf"[..]).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 | = note: `#[warn(temporary_cstring_as_ptr)]` on by default = 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 --- pnet_datalink/src/bpf.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pnet_datalink/src/bpf.rs b/pnet_datalink/src/bpf.rs index f263f3d5..52ee1797 100644 --- a/pnet_datalink/src/bpf.rs +++ b/pnet_datalink/src/bpf.rs @@ -82,9 +82,10 @@ pub fn channel(network_interface: &NetworkInterface, config: Config) -> io::Resu target_os = "solaris" ))] fn get_fd(_attempts: usize) -> libc::c_int { + let c_file_name = CString::new(&b"/dev/bpf"[..]).unwrap(); unsafe { libc::open( - CString::new(&b"/dev/bpf"[..]).unwrap().as_ptr(), + c_file_name.as_ptr(), libc::O_RDWR, 0, )