From eb64585d3c7152ebf9e3d1bf07b47de8ff09718e Mon Sep 17 00:00:00 2001 From: missing Date: Sun, 25 Dec 2022 22:43:23 -0600 Subject: [PATCH] clarify provenance issue in `new_owned` --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 72b2037..7761f6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,9 @@ impl Stringish { /// Alternatively, use the [`Ish::ish`] method. #[must_use] pub fn new_owned(s: String) -> Self { + // converting to a `Vec` is necessary since `s.as_mut_ptr()` would call `str::as_mut_ptr` + // through deref coercion, which would only give us a pointer with provenance to the + // initialized part of the `String`, which is not enough to deallocate. let mut v = ManuallyDrop::new(s.into_bytes()); Self { // SAFETY: `v.as_mut_ptr()` is never null