Skip to content

Commit 389e1e2

Browse files
committed
Removing usage of mem::uninitialized() and deprecating the blank() functions
Signed-off-by: Elichai Turkel <[email protected]>
1 parent dfe7ee5 commit 389e1e2

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/ffi.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ impl PublicKey {
7777
/// Create a new (zeroed) public key usable for the FFI interface
7878
pub fn new() -> PublicKey { PublicKey([0; 64]) }
7979
/// Create a new (uninitialized) public key usable for the FFI interface
80-
pub unsafe fn blank() -> PublicKey { mem::uninitialized() }
80+
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
81+
pub unsafe fn blank() -> PublicKey { PublicKey::new() }
8182
}
8283

8384
impl Default for PublicKey {
@@ -102,7 +103,8 @@ impl Signature {
102103
/// Create a new (zeroed) signature usable for the FFI interface
103104
pub fn new() -> Signature { Signature([0; 64]) }
104105
/// Create a new (uninitialized) signature usable for the FFI interface
105-
pub unsafe fn blank() -> Signature { mem::uninitialized() }
106+
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
107+
pub unsafe fn blank() -> Signature { Signature::new() }
106108
}
107109

108110
impl Default for Signature {
@@ -121,7 +123,8 @@ impl SharedSecret {
121123
/// Create a new (zeroed) signature usable for the FFI interface
122124
pub fn new() -> SharedSecret { SharedSecret([0; 32]) }
123125
/// Create a new (uninitialized) signature usable for the FFI interface
124-
pub unsafe fn blank() -> SharedSecret { mem::uninitialized() }
126+
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
127+
pub unsafe fn blank() -> SharedSecret { SharedSecret::new() }
125128
}
126129

127130
impl Default for SharedSecret {

src/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
#[cfg(any(test, feature = "rand"))] use rand::Rng;
1919

20-
use core::{fmt, mem, str};
20+
use core::{fmt, str};
2121

2222
use super::{from_hex, Secp256k1};
2323
use super::Error::{self, InvalidPublicKey, InvalidSecretKey};
@@ -338,7 +338,7 @@ impl PublicKey {
338338
/// to its own negation
339339
pub fn combine(&self, other: &PublicKey) -> Result<PublicKey, Error> {
340340
unsafe {
341-
let mut ret = mem::uninitialized();
341+
let mut ret = ffi::PublicKey::new();
342342
let ptrs = [self.as_ptr(), other.as_ptr()];
343343
if ffi::secp256k1_ec_pubkey_combine(
344344
ffi::secp256k1_context_no_precomp,

src/macros.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,8 @@ macro_rules! impl_array_newtype {
6868
impl Clone for $thing {
6969
#[inline]
7070
fn clone(&self) -> $thing {
71-
unsafe {
72-
use core::intrinsics::copy_nonoverlapping;
73-
use core::mem;
74-
let mut ret: $thing = mem::uninitialized();
75-
copy_nonoverlapping(self.as_ptr(),
76-
ret.as_mut_ptr(),
77-
$len);
78-
ret
79-
}
71+
let &$thing(ref dat) = self;
72+
$thing(dat.clone())
8073
}
8174
}
8275

src/recovery/ffi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ impl RecoverableSignature {
2929
/// Create a new (zeroed) signature usable for the FFI interface
3030
pub fn new() -> RecoverableSignature { RecoverableSignature([0; 65]) }
3131
/// Create a new (uninitialized) signature usable for the FFI interface
32-
pub unsafe fn blank() -> RecoverableSignature { mem::uninitialized() }
32+
#[deprecated(since = "0.15.3", note = "Please use the new function instead")]
33+
pub unsafe fn blank() -> RecoverableSignature { RecoverableSignature::new() }
3334
}
3435

3536
impl Default for RecoverableSignature {

0 commit comments

Comments
 (0)