Skip to content

Commit

Permalink
Updated the fuzzing dummy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai committed Jul 4, 2019
1 parent 811e8d2 commit 49f0cc1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use core::marker::PhantomData;
use {ffi, types::{c_uint, c_void}, Error, Secp256k1};
use ffi;
use types::{c_uint, c_void};
use Error;
use Secp256k1;

#[cfg(feature = "std")]
pub use self::std_only::*;
Expand Down
27 changes: 19 additions & 8 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ mod fuzz_dummy {
extern crate std;
use types::*;
use ffi::*;
use self::std::ptr;
use self::std::{ptr, mem};
use self::std::boxed::Box;

extern "C" {
Expand All @@ -335,20 +335,31 @@ mod fuzz_dummy {

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

/// Return dummy size of context struct.
pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize {
mem::size_of::<Context>()
}

/// Return dummy size of context struct.
pub unsafe fn secp256k1_context_preallocated_clone_size(cx: *mut Context) -> usize {
mem::size_of::<Context>()
}

/// Copies a dummy context
pub unsafe fn secp256k1_context_clone(cx: *mut Context) -> *mut Context {
let b = Box::new(Context((*cx).0));
Box::into_raw(b)
pub unsafe fn secp256k1_context_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context {
let ret = prealloc as *mut Context;
*ret = (*cx).clone();
ret
}

/// Frees a dummy context
pub unsafe fn secp256k1_context_destroy(cx: *mut Context) {
Box::from_raw(cx);
/// "Destroys" a dummy context
pub unsafe fn secp256k1_context_preallocated_destroy(cx: *mut Context) {
(*cx).0 = 0;
}

/// Asserts that cx is properly initialized
Expand Down

0 comments on commit 49f0cc1

Please sign in to comment.