summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2019-09-10 18:08:01 +0200
committerChristian Duerr <contact@christianduerr.com>2019-09-10 16:08:01 +0000
commit1067fa609b6a5a0017814cb96d8b21b39b2f83f2 (patch)
tree4b71a2863f0efdbc5aeb3a8f36234f85e59f7eec /alacritty_terminal
parent8aa406b98b3932a47a05ac8d71b4704198acd6f2 (diff)
Replace uninitialized with MaybeUninit
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/term/cell.rs8
-rw-r--r--alacritty_terminal/src/term/color.rs2
-rw-r--r--alacritty_terminal/src/tty/unix.rs7
3 files changed, 9 insertions, 8 deletions
diff --git a/alacritty_terminal/src/term/cell.rs b/alacritty_terminal/src/term/cell.rs
index 5e2762d2..8d1b135c 100644
--- a/alacritty_terminal/src/term/cell.rs
+++ b/alacritty_terminal/src/term/cell.rs
@@ -138,14 +138,14 @@ impl Cell {
#[inline]
pub fn chars(&self) -> [char; MAX_ZEROWIDTH_CHARS + 1] {
unsafe {
- let mut chars = [std::mem::uninitialized(); MAX_ZEROWIDTH_CHARS + 1];
- std::ptr::write(&mut chars[0], self.c);
+ let mut chars = [std::mem::MaybeUninit::uninit(); MAX_ZEROWIDTH_CHARS + 1];
+ std::ptr::write(chars[0].as_mut_ptr(), self.c);
std::ptr::copy_nonoverlapping(
- self.extra.as_ptr(),
+ self.extra.as_ptr() as *mut std::mem::MaybeUninit<char>,
chars.as_mut_ptr().offset(1),
self.extra.len(),
);
- chars
+ std::mem::transmute(chars)
}
}
diff --git a/alacritty_terminal/src/term/color.rs b/alacritty_terminal/src/term/color.rs
index 877d89e5..f2db335a 100644
--- a/alacritty_terminal/src/term/color.rs
+++ b/alacritty_terminal/src/term/color.rs
@@ -143,7 +143,7 @@ pub struct List([Rgb; COUNT]);
impl<'a> From<&'a Colors> for List {
fn from(colors: &Colors) -> List {
// Type inference fails without this annotation
- let mut list: List = unsafe { ::std::mem::uninitialized() };
+ let mut list = List([Rgb::default(); COUNT]);
list.fill_named(colors);
list.fill_cube(colors);
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 8ed8ba03..e666eeba 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -13,7 +13,6 @@
// limitations under the License.
//
//! tty related functionality
-//!
use crate::config::{Config, Shell};
use crate::display::OnResize;
@@ -36,6 +35,7 @@ use std::os::unix::{
use std::process::{Child, Command, Stdio};
use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};
+use std::mem::MaybeUninit;
/// Process ID of child process
///
@@ -91,15 +91,16 @@ struct Passwd<'a> {
/// If `buf` is changed while `Passwd` is alive, bad thing will almost certainly happen.
fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd<'_> {
// Create zeroed passwd struct
- let mut entry: libc::passwd = unsafe { ::std::mem::uninitialized() };
+ let mut entry: MaybeUninit<libc::passwd> = MaybeUninit::uninit();
let mut res: *mut libc::passwd = ptr::null_mut();
// Try and read the pw file.
let uid = unsafe { libc::getuid() };
let status = unsafe {
- libc::getpwuid_r(uid, &mut entry, buf.as_mut_ptr() as *mut _, buf.len(), &mut res)
+ libc::getpwuid_r(uid, entry.as_mut_ptr(), buf.as_mut_ptr() as *mut _, buf.len(), &mut res)
};
+ let entry = unsafe { entry.assume_init() };
if status < 0 {
die!("getpwuid_r failed");