Skip to content

Commit b983ef4

Browse files
committed
Updated the fuzzing dummy functions
1 parent 811e8d2 commit b983ef4

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Diff for: src/ffi.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ mod fuzz_dummy {
326326
use ffi::*;
327327
use self::std::ptr;
328328
use self::std::boxed::Box;
329+
use std::mem;
329330

330331
extern "C" {
331332
pub static secp256k1_ecdh_hash_function_default: EcdhHashFn;
@@ -335,20 +336,31 @@ mod fuzz_dummy {
335336

336337
// Contexts
337338
/// Creates a dummy context, tracking flags to ensure proper calling semantics
338-
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
339+
pub unsafe fn secp256k1_context_preallocated_create(_ptr: *mut c_void, flags: c_uint) -> *mut Context {
339340
let b = Box::new(Context(flags as i32));
340341
Box::into_raw(b)
341342
}
342343

344+
/// Return dummy size of context struct.
345+
pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize {
346+
mem::size_of::<Context>()
347+
}
348+
349+
/// Return dummy size of context struct.
350+
pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize {
351+
mem::size_of::<Context>()
352+
}
353+
343354
/// Copies a dummy context
344-
pub unsafe fn secp256k1_context_clone(cx: *mut Context) -> *mut Context {
345-
let b = Box::new(Context((*cx).0));
346-
Box::into_raw(b)
355+
pub unsafe fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context {
356+
let ret = prealloc as *mut Context;
357+
*ret = (*cx).clone();
358+
ret
347359
}
348360

349-
/// Frees a dummy context
350-
pub unsafe fn secp256k1_context_destroy(cx: *mut Context) {
351-
Box::from_raw(cx);
361+
/// "Destroys" a dummy context
362+
pub unsafe fn secp256k1_context_preallocated_destroy(cx: *mut Context) {
363+
(*cx).0 = 0;
352364
}
353365

354366
/// Asserts that cx is properly initialized

0 commit comments

Comments
 (0)