From e9b14ae189edb025d9909e581ddcabf937097150 Mon Sep 17 00:00:00 2001 From: Joseph Birr-Pixton Date: Wed, 10 Apr 2024 15:13:31 +0100 Subject: [PATCH] error.rs: eliminate an `unsafe` using c"" strings --- rustls-libssl/src/error.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rustls-libssl/src/error.rs b/rustls-libssl/src/error.rs index c1c6030..d444296 100644 --- a/rustls-libssl/src/error.rs +++ b/rustls-libssl/src/error.rs @@ -1,6 +1,6 @@ use core::ffi::{c_int, c_long}; use core::ptr; -use std::ffi::{CStr, CString}; +use std::ffi::CString; use openssl_sys::{ERR_new, ERR_set_error, ERR_RFLAGS_OFFSET, ERR_RFLAG_FATAL}; use rustls::AlertDescription; @@ -125,8 +125,6 @@ impl Error { .unwrap_or_else(|| format!("{:?}", self.reason)), ) .unwrap(); - // safety: b"%s\0" satisfies requirements of from_bytes_with_nul_unchecked. - let fmt = unsafe { CStr::from_bytes_with_nul_unchecked(b"%s\0") }; unsafe { ERR_new(); // nb. miri cannot do variadic functions, so we define a miri-only equivalent @@ -134,7 +132,7 @@ impl Error { ERR_set_error( self.lib as c_int, self.reason.into(), - fmt.as_ptr(), + c"%s".as_ptr(), cstr.as_ptr(), ); #[cfg(miri)]