]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: fix warnings found by nightly compiler
authorPhilippe Antoine <contact@catenacyber.fr>
Thu, 19 Nov 2020 14:50:54 +0000 (15:50 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Thu, 3 Dec 2020 22:39:55 +0000 (04:09 +0530)
warning: getting the inner pointer of a temporary `CString`
this `CString` is deallocated at the end of the statement,
bind it to a variable to extend its lifetime

(cherry picked from commit 8db78208f94db524c98af3f84caf6a8951e0d884)

rust/src/conf.rs

index e5b40f8447589152a6f851d94cc2da13f85a6966..92d3ccd696873196149ace0d040ef5a9a44f01c8 100644 (file)
@@ -37,7 +37,8 @@ pub fn conf_get(key: &str) -> Option<&str> {
     let mut vptr: *const c_char = ptr::null_mut();
 
     unsafe {
-        if ConfGet(CString::new(key).unwrap().as_ptr(), &mut vptr) != 1 {
+        let s = CString::new(key).unwrap();
+        if ConfGet(s.as_ptr(), &mut vptr) != 1 {
             SCLogDebug!("Failed to find value for key {}", key);
             return None;
         }
@@ -90,8 +91,9 @@ impl ConfNode {
         let mut vptr: *const c_char = ptr::null_mut();
 
         unsafe {
+            let s = CString::new(key).unwrap();
             if ConfGetChildValue(self.conf,
-                                 CString::new(key).unwrap().as_ptr(),
+                                 s.as_ptr(),
                                  &mut vptr) != 1 {
                 return None;
             }
@@ -112,8 +114,9 @@ impl ConfNode {
         let mut vptr: c_int = 0;
 
         unsafe {
+            let s = CString::new(key).unwrap();
             if ConfGetChildValueBool(self.conf,
-                                     CString::new(key).unwrap().as_ptr(),
+                                     s.as_ptr(),
                                      &mut vptr) != 1 {
                 return false;
             }