]> git.nihav.org Git - nihav.git/commitdiff
nihav_core/sbbox: try slightly less undefined code for SelfBorrow::end() master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 1 Feb 2026 19:55:40 +0000 (20:55 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 1 Feb 2026 19:55:40 +0000 (20:55 +0100)
nihav-core/src/sbbox.rs

index e1ee6e3187cc2688f05ed1211811ed906d3dca06..3b58ac3d8e51ac39efaa4a0ee95da1208502480c 100644 (file)
@@ -89,10 +89,10 @@ impl<T: Unpin, U: Unpin> SelfBorrow<T, U> {
     pub fn end(mut boxed: SBBox<T, U>) -> 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::<SelfBorrow<T, U>>());
             ret
         }