From c9d7c2a48425889fb15e3195e390ee44d4a614f1 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 1 Sep 2015 01:44:02 +0000 Subject: [PATCH] secp256k1_context_set_{error,illegal}_callback: Restore default handler by passing NULL as function argument --- include/secp256k1.h | 9 +++++---- src/secp256k1.c | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/secp256k1.h b/include/secp256k1.h index 07a77bf7b7acb..0b2620d4705e0 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 133ab9bbfbfff..3334dd3c86d3d 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; }