From ff7f74fd29945ec7913c7b99fd743298164c7888 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Wed, 15 Jun 2022 22:07:32 +0200 Subject: Use `MaybeUninit` instead of `usize` in `Storage::swap` `Row` contains pointer bytes, which are not valid for `usize`, therefore `MaybeUninit` should be used instead to do an untyped copy. --- alacritty_terminal/src/grid/storage.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/alacritty_terminal/src/grid/storage.rs b/alacritty_terminal/src/grid/storage.rs index 6fbc3bf2..e444d9c3 100644 --- a/alacritty_terminal/src/grid/storage.rs +++ b/alacritty_terminal/src/grid/storage.rs @@ -1,5 +1,6 @@ use std::cmp::{max, PartialEq}; use std::mem; +use std::mem::MaybeUninit; use std::ops::{Index, IndexMut}; use serde::{Deserialize, Serialize}; @@ -157,13 +158,13 @@ impl Storage { // Cast to a qword array to opt out of copy restrictions and avoid // drop hazards. Byte array is no good here since for whatever // reason LLVM won't optimized it. - let a_ptr = self.inner.as_mut_ptr().add(a) as *mut usize; - let b_ptr = self.inner.as_mut_ptr().add(b) as *mut usize; + let a_ptr = self.inner.as_mut_ptr().add(a) as *mut MaybeUninit; + let b_ptr = self.inner.as_mut_ptr().add(b) as *mut MaybeUninit; // Copy 1 qword at a time. // // The optimizer unrolls this loop and vectorizes it. - let mut tmp: usize; + let mut tmp: MaybeUninit; for i in 0..4 { tmp = *a_ptr.offset(i); *a_ptr.offset(i) = *b_ptr.offset(i); -- cgit v1.2.3-54-g00ecf