Skip to content

Commit

Permalink
secp256k1_context_set_{error,illegal}_callback: Restore default handl…
Browse files Browse the repository at this point in the history
…er by passing NULL as function argument
  • Loading branch information
luke-jr committed Sep 19, 2015
1 parent 9aac008 commit c9d7c2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/secp256k1.h
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions src/secp256k1.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit c9d7c2a

Please sign in to comment.