Removing usage of `mem::uninitialized()` and deprecating the `blank()` functions

Signed-off-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
Elichai Turkel 2019-08-08 17:19:31 -04:00
parent dfe7ee54f9
commit 389e1e2449
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
4 changed files with 12 additions and 15 deletions

View File

@ -77,7 +77,8 @@ impl PublicKey {
/// Create a new (zeroed) public key usable for the FFI interface /// Create a new (zeroed) public key usable for the FFI interface
pub fn new() -> PublicKey { PublicKey([0; 64]) } pub fn new() -> PublicKey { PublicKey([0; 64]) }
/// Create a new (uninitialized) public key usable for the FFI interface /// 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 { impl Default for PublicKey {
@ -102,7 +103,8 @@ impl Signature {
/// Create a new (zeroed) signature usable for the FFI interface /// Create a new (zeroed) signature usable for the FFI interface
pub fn new() -> Signature { Signature([0; 64]) } pub fn new() -> Signature { Signature([0; 64]) }
/// Create a new (uninitialized) signature usable for the FFI interface /// 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 { impl Default for Signature {
@ -121,7 +123,8 @@ impl SharedSecret {
/// Create a new (zeroed) signature usable for the FFI interface /// Create a new (zeroed) signature usable for the FFI interface
pub fn new() -> SharedSecret { SharedSecret([0; 32]) } pub fn new() -> SharedSecret { SharedSecret([0; 32]) }
/// Create a new (uninitialized) signature usable for the FFI interface /// 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 { impl Default for SharedSecret {

View File

@ -17,7 +17,7 @@
#[cfg(any(test, feature = "rand"))] use rand::Rng; #[cfg(any(test, feature = "rand"))] use rand::Rng;
use core::{fmt, mem, str}; use core::{fmt, str};
use super::{from_hex, Secp256k1}; use super::{from_hex, Secp256k1};
use super::Error::{self, InvalidPublicKey, InvalidSecretKey}; use super::Error::{self, InvalidPublicKey, InvalidSecretKey};
@ -338,7 +338,7 @@ impl PublicKey {
/// to its own negation /// to its own negation
pub fn combine(&self, other: &PublicKey) -> Result<PublicKey, Error> { pub fn combine(&self, other: &PublicKey) -> Result<PublicKey, Error> {
unsafe { unsafe {
let mut ret = mem::uninitialized(); let mut ret = ffi::PublicKey::new();
let ptrs = [self.as_ptr(), other.as_ptr()]; let ptrs = [self.as_ptr(), other.as_ptr()];
if ffi::secp256k1_ec_pubkey_combine( if ffi::secp256k1_ec_pubkey_combine(
ffi::secp256k1_context_no_precomp, ffi::secp256k1_context_no_precomp,

View File

@ -68,15 +68,8 @@ macro_rules! impl_array_newtype {
impl Clone for $thing { impl Clone for $thing {
#[inline] #[inline]
fn clone(&self) -> $thing { fn clone(&self) -> $thing {
unsafe { let &$thing(ref dat) = self;
use core::intrinsics::copy_nonoverlapping; $thing(dat.clone())
use core::mem;
let mut ret: $thing = mem::uninitialized();
copy_nonoverlapping(self.as_ptr(),
ret.as_mut_ptr(),
$len);
ret
}
} }
} }

View File

@ -29,7 +29,8 @@ impl RecoverableSignature {
/// Create a new (zeroed) signature usable for the FFI interface /// Create a new (zeroed) signature usable for the FFI interface
pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) } pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) }
/// Create a new (uninitialized) signature usable for the FFI interface /// 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 { impl Default for RecoverableSignature {