From 2e25d56f3459d7cfcbea9e0f97512ff4f09c7fbb Mon Sep 17 00:00:00 2001 From: Mike Zeller Date: Tue, 21 Nov 2023 21:48:06 +0000 Subject: [PATCH] Address andy's feedback --- ipcc/src/ffi.rs | 5 ++++- ipcc/src/handle.rs | 5 ++--- ipcc/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ipcc/src/ffi.rs b/ipcc/src/ffi.rs index a96d6986ac..1d228ee877 100644 --- a/ipcc/src/ffi.rs +++ b/ipcc/src/ffi.rs @@ -42,7 +42,10 @@ pub(crate) const LIBIPCC_ERR_KEY_VALTOOLONG: libipcc_err_t = 7; pub(crate) const LIBIPCC_ERR_KEY_ZERR: libipcc_err_t = 8; pub(crate) type libipcc_err_t = c_uint; -pub type libipcc_key_flag_t = ::std::os::raw::c_uint; +/// Maxium length of an error message retrieved by libipcc_errmsg(). +pub(crate) const LIBIPCC_ERR_LEN: usize = 1024; + +pub(crate) type libipcc_key_flag_t = ::std::os::raw::c_uint; #[link(name = "ipcc")] extern "C" { diff --git a/ipcc/src/handle.rs b/ipcc/src/handle.rs index d5f47d436d..26f9e830bb 100644 --- a/ipcc/src/handle.rs +++ b/ipcc/src/handle.rs @@ -31,8 +31,7 @@ fn ipcc_fatal_error>( let syserr = if syserr == 0 { "no system errno".to_string() } else { - let syserr = unsafe { libc::strerror(syserr) }; - unsafe { CStr::from_ptr(syserr) }.to_string_lossy().into_owned() + std::io::Error::from_raw_os_error(syserr).to_string() }; let inner = IpccErrorInner { context, @@ -56,7 +55,7 @@ fn ipcc_fatal_error>( impl IpccHandle { pub fn new() -> Result { let mut ipcc_handle: *mut libipcc_handle_t = ptr::null_mut(); - let errmsg = CString::new(vec![1; 1024]).unwrap(); + let errmsg = CString::new(vec![1; LIBIPCC_ERR_LEN]).unwrap(); let errmsg_len = errmsg.as_bytes().len(); let errmsg_ptr = errmsg.into_raw(); let mut lerr = LIBIPCC_ERR_OK; diff --git a/ipcc/src/lib.rs b/ipcc/src/lib.rs index 6a8c51adc6..d00cf71770 100644 --- a/ipcc/src/lib.rs +++ b/ipcc/src/lib.rs @@ -173,7 +173,7 @@ pub struct IpccErrorInner { pub syserr: String, } -/// These are the IPCC keys we can lookup. +/// These are the IPCC keys we can look up. /// NB: These keys match the definitions found in libipcc (RFD 316) and should /// match the values in `[ipcc::Key]` one-to-one. #[derive(Debug, Clone, Copy)]