Skip to content

Commit 49f0cc1

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

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use core::marker::PhantomData;
2-
use {ffi, types::{c_uint, c_void}, Error, Secp256k1};
2+
use ffi;
3+
use types::{c_uint, c_void};
4+
use Error;
5+
use Secp256k1;
36

47
#[cfg(feature = "std")]
58
pub use self::std_only::*;

src/ffi.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ mod fuzz_dummy {
324324
extern crate std;
325325
use types::*;
326326
use ffi::*;
327-
use self::std::ptr;
327+
use self::std::{ptr, mem};
328328
use self::std::boxed::Box;
329329

330330
extern "C" {
@@ -335,20 +335,31 @@ mod fuzz_dummy {
335335

336336
// Contexts
337337
/// Creates a dummy context, tracking flags to ensure proper calling semantics
338-
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
338+
pub unsafe fn secp256k1_context_preallocated_create(_ptr: *mut c_void, flags: c_uint) -> *mut Context {
339339
let b = Box::new(Context(flags as i32));
340340
Box::into_raw(b)
341341
}
342342

343+
/// Return dummy size of context struct.
344+
pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize {
345+
mem::size_of::<Context>()
346+
}
347+
348+
/// Return dummy size of context struct.
349+
pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize {
350+
mem::size_of::<Context>()
351+
}
352+
343353
/// 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)
354+
pub unsafe fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context {
355+
let ret = prealloc as *mut Context;
356+
*ret = (*cx).clone();
357+
ret
347358
}
348359

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

354365
/// Asserts that cx is properly initialized

0 commit comments

Comments
 (0)