diff --git a/include/secp256k1.h b/include/secp256k1.h index 07a77bf..0b2620d 100644 --- a/include/secp256k1.h +++ b/include/secp256k1.h @@ -179,14 +179,14 @@ void secp256k1_context_destroy( * Args: ctx: an existing context object (cannot be NULL) * In: fun: a pointer to a function to call when an illegal argument is * passed to the API, taking a message and an opaque pointer - * (cannot be NULL). + * (NULL restores a default handler that calls abort). * data: the opaque pointer to pass to fun above. */ void secp256k1_context_set_illegal_callback( secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); +) SECP256K1_ARG_NONNULL(1); /** Set a callback function to be called when an internal consistency check * fails. The default is crashing. @@ -200,14 +200,15 @@ void secp256k1_context_set_illegal_callback( * * Args: ctx: an existing context object (cannot be NULL) * In: fun: a pointer to a function to call when an interal error occurs, - * taking a message and an opaque pointer (cannot be NULL). + * taking a message and an opaque pointer (NULL restores a default + * handler that calls abort). * data: the opaque pointer to pass to fun above. */ void secp256k1_context_set_error_callback( secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data -) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2); +) SECP256K1_ARG_NONNULL(1); /** Parse a variable-length public key into the pubkey object. * diff --git a/src/secp256k1.c b/src/secp256k1.c index 133ab9b..3334dd3 100644 --- a/src/secp256k1.c +++ b/src/secp256k1.c @@ -95,11 +95,15 @@ void secp256k1_context_destroy(secp256k1_context_t* ctx) { } void secp256k1_context_set_illegal_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) { + if (!fun) + fun = default_illegal_callback_fn; ctx->illegal_callback.fn = fun; ctx->illegal_callback.data = data; } void secp256k1_context_set_error_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) { + if (!fun) + fun = default_error_callback_fn; ctx->error_callback.fn = fun; ctx->error_callback.data = data; }