Skip to content

Commit c9d7c2a

Browse files
committed
secp256k1_context_set_{error,illegal}_callback: Restore default handler by passing NULL as function argument
1 parent 9aac008 commit c9d7c2a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/secp256k1.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ void secp256k1_context_destroy(
179179
* Args: ctx: an existing context object (cannot be NULL)
180180
* In: fun: a pointer to a function to call when an illegal argument is
181181
* passed to the API, taking a message and an opaque pointer
182-
* (cannot be NULL).
182+
* (NULL restores a default handler that calls abort).
183183
* data: the opaque pointer to pass to fun above.
184184
*/
185185
void secp256k1_context_set_illegal_callback(
186186
secp256k1_context_t* ctx,
187187
void (*fun)(const char* message, void* data),
188188
void* data
189-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
189+
) SECP256K1_ARG_NONNULL(1);
190190

191191
/** Set a callback function to be called when an internal consistency check
192192
* fails. The default is crashing.
@@ -200,14 +200,15 @@ void secp256k1_context_set_illegal_callback(
200200
*
201201
* Args: ctx: an existing context object (cannot be NULL)
202202
* In: fun: a pointer to a function to call when an interal error occurs,
203-
* taking a message and an opaque pointer (cannot be NULL).
203+
* taking a message and an opaque pointer (NULL restores a default
204+
* handler that calls abort).
204205
* data: the opaque pointer to pass to fun above.
205206
*/
206207
void secp256k1_context_set_error_callback(
207208
secp256k1_context_t* ctx,
208209
void (*fun)(const char* message, void* data),
209210
void* data
210-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2);
211+
) SECP256K1_ARG_NONNULL(1);
211212

212213
/** Parse a variable-length public key into the pubkey object.
213214
*

src/secp256k1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ void secp256k1_context_destroy(secp256k1_context_t* ctx) {
9595
}
9696

9797
void secp256k1_context_set_illegal_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) {
98+
if (!fun)
99+
fun = default_illegal_callback_fn;
98100
ctx->illegal_callback.fn = fun;
99101
ctx->illegal_callback.data = data;
100102
}
101103

102104
void secp256k1_context_set_error_callback(secp256k1_context_t* ctx, void (*fun)(const char* message, void* data), void* data) {
105+
if (!fun)
106+
fun = default_error_callback_fn;
103107
ctx->error_callback.fn = fun;
104108
ctx->error_callback.data = data;
105109
}

0 commit comments

Comments
 (0)