From d395a01e7c191bc38989b67ea825c16a07adfa36 Mon Sep 17 00:00:00 2001 From: bluss Date: Sat, 15 Dec 2018 14:51:00 +0100 Subject: [PATCH] FIX: Remove use of uninitialized in ArrayString We can't fix this properly (MaybeUninit with a union) until we change the user visible API (we need to require that A: Copy. As a temporary solution for arrayvec version 0.4.*, we use zeroed to initialize an array of bytes, instead of using uninitialized. This may have a negative performance impact, but the fix is to upgrade to future arrayvec 0.5. --- src/array_string.rs | 4 +++- src/lib.rs | 8 -------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/array_string.rs b/src/array_string.rs index 0dc0974..6cd1c65 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -26,6 +26,7 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer}; /// if needed. #[derive(Copy)] pub struct ArrayString> { + // FIXME: Use Copyable union for xs when we can xs: A, len: A::Index, } @@ -53,7 +54,8 @@ impl> ArrayString { pub fn new() -> ArrayString { unsafe { ArrayString { - xs: ::new_array(), + // FIXME: Use Copyable union for xs when we can + xs: mem::zeroed(), len: Index::from(0), } } diff --git a/src/lib.rs b/src/lib.rs index 9579114..cd8f0b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,14 +74,6 @@ pub use array_string::ArrayString; pub use errors::CapacityError; -unsafe fn new_array() -> A { - // Note: Returning an uninitialized value here only works - // if we can be sure the data is never used. The nullable pointer - // inside enum optimization conflicts with this this for example, - // so we need to be extra careful. See `NoDrop` enum. - mem::uninitialized() -} - /// A vector with a fixed capacity. /// /// The `ArrayVec` is a vector backed by a fixed size array. It keeps track of