Updated the fuzzing dummy functions

This commit is contained in:
Elichai Turkel 2019-07-04 19:03:13 -04:00
parent 811e8d24e9
commit 49f0cc1c46
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
2 changed files with 24 additions and 10 deletions

View File

@ -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::*;

View File

@ -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" {
@ -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)
}
/// 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)
/// Return dummy size of context struct.
pub unsafe fn secp256k1_context_preallocated_size(_flags: c_uint) -> usize {
mem::size_of::<Context>()
}
/// Frees a dummy context
pub unsafe fn secp256k1_context_destroy(cx: *mut Context) {
Box::from_raw(cx);
/// 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_preallocated_clone(cx: *const Context, prealloc: *mut c_void) -> *mut Context {
let ret = prealloc as *mut Context;
*ret = (*cx).clone();
ret
}
/// "Destroys" a dummy context
pub unsafe fn secp256k1_context_preallocated_destroy(cx: *mut Context) {
(*cx).0 = 0;
}
/// Asserts that cx is properly initialized