File tree 2 files changed +9
-0
lines changed
2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -798,6 +798,9 @@ pub unsafe extern "C" fn rustsecp256k1_v0_6_1_context_create(flags: c_uint) -> *
798
798
let bytes = secp256k1_context_preallocated_size ( flags) + ALIGN_TO ;
799
799
let layout = alloc:: Layout :: from_size_align ( bytes, ALIGN_TO ) . unwrap ( ) ;
800
800
let ptr = alloc:: alloc ( layout) ;
801
+ if ptr. is_null ( ) {
802
+ alloc:: handle_alloc_error ( layout) ;
803
+ }
801
804
( ptr as * mut usize ) . write ( bytes) ;
802
805
// We must offset a whole ALIGN_TO in order to preserve the same alignment
803
806
// this means we "lose" ALIGN_TO-size_of(usize) for padding.
Original file line number Diff line number Diff line change @@ -194,6 +194,9 @@ mod alloc_only {
194
194
let size = unsafe { ffi:: secp256k1_context_preallocated_size ( C :: FLAGS ) } ;
195
195
let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
196
196
let ptr = unsafe { alloc:: alloc ( layout) } ;
197
+ if ptr. is_null ( ) {
198
+ alloc:: handle_alloc_error ( layout) ;
199
+ }
197
200
198
201
#[ allow( unused_mut) ] // ctx is not mutated under some feature combinations.
199
202
let mut ctx = Secp256k1 {
@@ -254,6 +257,9 @@ mod alloc_only {
254
257
let size = unsafe { ffi:: secp256k1_context_preallocated_clone_size ( self . ctx as _ ) } ;
255
258
let layout = alloc:: Layout :: from_size_align ( size, ALIGN_TO ) . unwrap ( ) ;
256
259
let ptr = unsafe { alloc:: alloc ( layout) } ;
260
+ if ptr. is_null ( ) {
261
+ alloc:: handle_alloc_error ( layout) ;
262
+ }
257
263
Secp256k1 {
258
264
ctx : unsafe {
259
265
ffi:: secp256k1_context_preallocated_clone ( self . ctx , ptr as * mut c_void )
You can’t perform that action at this time.
0 commit comments