diff options
author | Daniel McCarney <daniel@binaryparadox.net> | 2024-09-09 15:33:57 -0400 |
---|---|---|
committer | Daniel McCarney <daniel@binaryparadox.net> | 2024-09-10 08:09:21 -0400 |
commit | e084c94e130f77b1c91d24c5e3cbb252e51c1d51 (patch) | |
tree | 6771b5beedf87f473ab450ddee09be5b8c31d2c0 /src/connection.rs | |
parent | b4d61cc1f6c45bdff7c2a9c79a1bdef1d653abb3 (diff) |
lib: add try_slice_mut! macro
This is a companion to the existing `try_slice!` macro, but returning
a `&mut` slice using `slice::from_raw_parts_mut()` instead of
`slice::from_raw_parts()`.
Two existing callers to `slice::from_raw_parts_mut()` in `connection.rs`
are converted to use the macro.
Diffstat (limited to 'src/connection.rs')
-rw-r--r-- | src/connection.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/connection.rs b/src/connection.rs index 602b169..c9d418f 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -17,7 +17,7 @@ use crate::log::{ensure_log_registered, rustls_log_callback}; use crate::rslice::rustls_str; use crate::{ box_castable, ffi_panic_boundary, free_box, try_callback, try_mut_from_ptr, try_ref_from_ptr, - try_slice, userdata_push, + try_slice, try_slice_mut, userdata_push, }; use rustls_result::NullParameter; @@ -491,7 +491,7 @@ impl rustls_connection { // Safety: the memory pointed at by buf must be initialized // (required by documentation of this function). - let read_buf = unsafe { slice::from_raw_parts_mut(buf, count) }; + let read_buf = try_slice_mut!(buf, count); let n_read = match conn.reader().read(read_buf) { Ok(n) => n, @@ -536,9 +536,7 @@ impl rustls_connection { if buf.is_null() || out_n.is_null() { return NullParameter; } - let read_buf = unsafe { slice::from_raw_parts_mut(buf, count) }; - - let mut read_buf: std::io::BorrowedBuf<'_> = read_buf.into(); + let mut read_buf: std::io::BorrowedBuf<'_> = try_slice_mut!(buf, count).into(); let n_read = match conn.reader().read_buf(read_buf.unfilled()) { Ok(()) => read_buf.filled().len(), |