]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
rust: Replace two `unwrap()`s in FFI code with `unwrap_or()`s.
authorIsis Lovecruft <isis@torproject.org>
Sat, 10 Feb 2018 01:21:31 +0000 (01:21 +0000)
committerIsis Lovecruft <isis@torproject.org>
Sat, 10 Feb 2018 01:21:31 +0000 (01:21 +0000)
src/rust/protover/ffi.rs
src/rust/protover/protover.rs

index d724c102d3cf3e8665ccdc4fdc5ff3c152f7a0a2..2ee0286ecf4d16cc0db9e5770e190e1ccefb99fe 100644 (file)
@@ -232,7 +232,7 @@ pub extern "C" fn protover_compute_for_old_tor(version: *const c_char) -> *const
     // we can see that the bytes we're passing into it 1) are valid UTF-8,
     // 2) have no intermediate NUL bytes, and 3) are terminated with a NUL
     // byte.
-    supported = CStr::from_bytes_with_nul(elder_protocols).unwrap();
+    supported = CStr::from_bytes_with_nul(elder_protocols).unwrap_or(empty);
 
     supported.as_ptr()
 }
index 826f1b73f13fd7a7a7f49bdcb46ac0d625e7e06f..25f776aed4ecf0352daa7875bbaa26f7d5b95f1e 100644 (file)
@@ -110,7 +110,7 @@ pub fn get_supported_protocols() -> &'static str {
     // The `unwrap` is safe becauase we SUPPORTED_PROTOCOLS is under
     // our control.
     str::from_utf8(&SUPPORTED_PROTOCOLS[..SUPPORTED_PROTOCOLS.len() - 1])
-        .unwrap()
+        .unwrap_or("")
 }
 
 pub struct SupportedProtocols(HashMap<Proto, Versions>);