From: Kostya Shishkov Date: Sun, 1 Feb 2026 19:55:40 +0000 (+0100) Subject: nihav_core/sbbox: try slightly less undefined code for SelfBorrow::end() X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=b35b46c5dd1eefb2960dc191cdf384ba54110f87;p=nihav.git nihav_core/sbbox: try slightly less undefined code for SelfBorrow::end() --- diff --git a/nihav-core/src/sbbox.rs b/nihav-core/src/sbbox.rs index e1ee6e3..3b58ac3 100644 --- a/nihav-core/src/sbbox.rs +++ b/nihav-core/src/sbbox.rs @@ -89,10 +89,10 @@ impl SelfBorrow { pub fn end(mut boxed: SBBox) -> T { boxed.dst = None; unsafe { - let mut unboxed = Pin::into_inner(boxed); - let ret_ = std::mem::MaybeUninit::uninit(); - let mut ret = ret_.assume_init(); - std::mem::swap(&mut ret, &mut unboxed.bval); + let mut cval = std::mem::MaybeUninit::uninit(); + std::ptr::copy_nonoverlapping(&boxed.bval as *const T, cval.as_mut_ptr(), 1); + let ret = cval.assume_init(); + let unboxed = Pin::into_inner(boxed); dealloc(Box::into_raw(unboxed) as *mut u8, Layout::new::>()); ret }