From 389e1e2449876e1ad6c027b48b895cf1c65de21d Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 8 Aug 2019 17:19:31 -0400 Subject: [PATCH] Removing usage of `mem::uninitialized()` and deprecating the `blank()` functions Signed-off-by: Elichai Turkel --- src/ffi.rs | 9 ++++++--- src/key.rs | 4 ++-- src/macros.rs | 11 ++--------- src/recovery/ffi.rs | 3 ++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index f5a4a98..3f28490 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -77,7 +77,8 @@ impl PublicKey { /// Create a new (zeroed) public key usable for the FFI interface pub fn new() -> PublicKey { PublicKey([0; 64]) } /// Create a new (uninitialized) public key usable for the FFI interface - pub unsafe fn blank() -> PublicKey { mem::uninitialized() } + #[deprecated(since = "0.15.3", note = "Please use the new function instead")] + pub unsafe fn blank() -> PublicKey { PublicKey::new() } } impl Default for PublicKey { @@ -102,7 +103,8 @@ impl Signature { /// Create a new (zeroed) signature usable for the FFI interface pub fn new() -> Signature { Signature([0; 64]) } /// Create a new (uninitialized) signature usable for the FFI interface - pub unsafe fn blank() -> Signature { mem::uninitialized() } + #[deprecated(since = "0.15.3", note = "Please use the new function instead")] + pub unsafe fn blank() -> Signature { Signature::new() } } impl Default for Signature { @@ -121,7 +123,8 @@ impl SharedSecret { /// Create a new (zeroed) signature usable for the FFI interface pub fn new() -> SharedSecret { SharedSecret([0; 32]) } /// Create a new (uninitialized) signature usable for the FFI interface - pub unsafe fn blank() -> SharedSecret { mem::uninitialized() } + #[deprecated(since = "0.15.3", note = "Please use the new function instead")] + pub unsafe fn blank() -> SharedSecret { SharedSecret::new() } } impl Default for SharedSecret { diff --git a/src/key.rs b/src/key.rs index e4e6ace..62d3ab2 100644 --- a/src/key.rs +++ b/src/key.rs @@ -17,7 +17,7 @@ #[cfg(any(test, feature = "rand"))] use rand::Rng; -use core::{fmt, mem, str}; +use core::{fmt, str}; use super::{from_hex, Secp256k1}; use super::Error::{self, InvalidPublicKey, InvalidSecretKey}; @@ -338,7 +338,7 @@ impl PublicKey { /// to its own negation pub fn combine(&self, other: &PublicKey) -> Result { unsafe { - let mut ret = mem::uninitialized(); + let mut ret = ffi::PublicKey::new(); let ptrs = [self.as_ptr(), other.as_ptr()]; if ffi::secp256k1_ec_pubkey_combine( ffi::secp256k1_context_no_precomp, diff --git a/src/macros.rs b/src/macros.rs index c36dc8b..3b41467 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -68,15 +68,8 @@ macro_rules! impl_array_newtype { impl Clone for $thing { #[inline] fn clone(&self) -> $thing { - unsafe { - use core::intrinsics::copy_nonoverlapping; - use core::mem; - let mut ret: $thing = mem::uninitialized(); - copy_nonoverlapping(self.as_ptr(), - ret.as_mut_ptr(), - $len); - ret - } + let &$thing(ref dat) = self; + $thing(dat.clone()) } } diff --git a/src/recovery/ffi.rs b/src/recovery/ffi.rs index 385f071..85bebe3 100644 --- a/src/recovery/ffi.rs +++ b/src/recovery/ffi.rs @@ -29,7 +29,8 @@ impl RecoverableSignature { /// Create a new (zeroed) signature usable for the FFI interface pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) } /// Create a new (uninitialized) signature usable for the FFI interface - pub unsafe fn blank() -> RecoverableSignature { mem::uninitialized() } + #[deprecated(since = "0.15.3", note = "Please use the new function instead")] + pub unsafe fn blank() -> RecoverableSignature { RecoverableSignature::new() } } impl Default for RecoverableSignature {