From 4690bfb071dc71daec12e821c882ca3082f1886d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 3 Jan 2023 15:53:29 -0800 Subject: [PATCH] review: perform UTF-8 check on `GuestStr` construction --- crates/wiggle/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wiggle/src/lib.rs b/crates/wiggle/src/lib.rs index 7496e1a60f39..fddd22f330e3 100644 --- a/crates/wiggle/src/lib.rs +++ b/crates/wiggle/src/lib.rs @@ -746,7 +746,7 @@ impl<'a> GuestPtr<'a, str> { /// a [`GuestStrCow::Borrowed`] (a thin wrapper over [`GuestStr<'_, T>]`). pub fn as_cow(&self) -> Result, GuestError> { match self.as_bytes().as_unsafe_slice_mut()?.shared_borrow() { - UnsafeBorrowResult::Ok(s) => Ok(GuestStrCow::Borrowed(GuestStr(s))), + UnsafeBorrowResult::Ok(s) => Ok(GuestStrCow::Borrowed(s.try_into()?)), UnsafeBorrowResult::Shared(_) => { let copied = self.as_bytes().to_vec()?; let utf8_string = String::from_utf8(copied).map_err(|e| e.utf8_error())?;