[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] rust/tor_util: drop unsafe block in cstr!



commit 2f0744b3e6f579f25db1ed6e048d0418ac2ab570
Author: cypherpunks <cypherpunks@xxxxxxxxxxxxxx>
Date:   Wed Oct 17 00:16:21 2018 +0000

    rust/tor_util: drop unsafe block in cstr!
    
    This is unnecessary just to get an empty string, there's Default::default().
    
    Fix on 8fff331bb095dc6f5e2fe2ecfc9ab08ea9e2fe97.
---
 changes/ticket28077          | 3 +++
 src/rust/tor_util/strings.rs | 6 +-----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/changes/ticket28077 b/changes/ticket28077
new file mode 100644
index 000000000..2b5afb167
--- /dev/null
+++ b/changes/ticket28077
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring:
+    - Remove unnecessarily unsafe code from the rust macro cstr!. Closes
+      ticket 28077.
diff --git a/src/rust/tor_util/strings.rs b/src/rust/tor_util/strings.rs
index d64275e06..71a908a58 100644
--- a/src/rust/tor_util/strings.rs
+++ b/src/rust/tor_util/strings.rs
@@ -105,11 +105,7 @@ macro_rules! cstr {
     ($($bytes:expr),*) => (
         ::std::ffi::CStr::from_bytes_with_nul(
             concat!($($bytes),*, "\0").as_bytes()
-        ).unwrap_or(
-            unsafe{
-                ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"\0")
-            }
-        )
+        ).unwrap_or_default()
     )
 }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits