Skip to content

Commit 433d40e

Browse files
committed
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.
1 parent 8c87087 commit 433d40e

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/array_string.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
2626
/// if needed.
2727
#[derive(Copy)]
2828
pub struct ArrayString<A: Array<Item=u8>> {
29+
// FIXME: Use Copyable union for xs when we can
2930
xs: A,
3031
len: A::Index,
3132
}
@@ -53,7 +54,8 @@ impl<A: Array<Item=u8>> ArrayString<A> {
5354
pub fn new() -> ArrayString<A> {
5455
unsafe {
5556
ArrayString {
56-
xs: ::new_array(),
57+
// FIXME: Use Copyable union for xs when we can
58+
xs: mem::zeroed(),
5759
len: Index::from(0),
5860
}
5961
}

src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ pub use array_string::ArrayString;
7474
pub use errors::CapacityError;
7575

7676

77-
unsafe fn new_array<A: Array>() -> A {
78-
// Note: Returning an uninitialized value here only works
79-
// if we can be sure the data is never used. The nullable pointer
80-
// inside enum optimization conflicts with this this for example,
81-
// so we need to be extra careful. See `NoDrop` enum.
82-
mem::uninitialized()
83-
}
84-
8577
/// A vector with a fixed capacity.
8678
///
8779
/// The `ArrayVec` is a vector backed by a fixed size array. It keeps track of

0 commit comments

Comments
 (0)