51
51
} \
52
52
} while(0)
53
53
54
- #define ARG_CHECK_NO_RETURN (cond ) do { \
54
+ #define ARG_CHECK_VOID (cond ) do { \
55
55
if (EXPECT(!(cond), 0)) { \
56
56
secp256k1_callback_call(&ctx->illegal_callback, #cond); \
57
+ return; \
57
58
} \
58
59
} while(0)
59
60
@@ -75,6 +76,15 @@ static const secp256k1_context secp256k1_context_static_ = {
75
76
const secp256k1_context * secp256k1_context_static = & secp256k1_context_static_ ;
76
77
const secp256k1_context * secp256k1_context_no_precomp = & secp256k1_context_static_ ;
77
78
79
+ /* Helper function that determines if a context is proper, i.e., is not the static context or a copy thereof.
80
+ *
81
+ * This is intended for "context" functions such as secp256k1_context_clone. Function which need specific
82
+ * features of a context should still check for these features directly. For example, a function that needs
83
+ * ecmult_gen should directly check for the existence of the ecmult_gen context. */
84
+ static int secp256k1_context_is_proper (const secp256k1_context * ctx ) {
85
+ return secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx );
86
+ }
87
+
78
88
void secp256k1_selftest (void ) {
79
89
if (!secp256k1_selftest_passes ()) {
80
90
secp256k1_callback_call (& default_error_callback , "self test failed" );
@@ -157,7 +167,7 @@ secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
157
167
}
158
168
159
169
void secp256k1_context_preallocated_destroy (secp256k1_context * ctx ) {
160
- ARG_CHECK_NO_RETURN (ctx != secp256k1_context_static );
170
+ ARG_CHECK_VOID (ctx != secp256k1_context_static );
161
171
if (ctx != NULL ) {
162
172
secp256k1_ecmult_gen_context_clear (& ctx -> ecmult_gen_ctx );
163
173
}
@@ -171,7 +181,10 @@ void secp256k1_context_destroy(secp256k1_context* ctx) {
171
181
}
172
182
173
183
void secp256k1_context_set_illegal_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
174
- ARG_CHECK_NO_RETURN (ctx != secp256k1_context_static );
184
+ /* We compare pointers instead of checking secp256k1_context_is_proper() here
185
+ because setting callbacks is allowed on *copies* of the static context:
186
+ it's harmless and makes testing easier. */
187
+ ARG_CHECK_VOID (ctx != secp256k1_context_static );
175
188
if (fun == NULL ) {
176
189
fun = secp256k1_default_illegal_callback_fn ;
177
190
}
@@ -180,7 +193,10 @@ void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(
180
193
}
181
194
182
195
void secp256k1_context_set_error_callback (secp256k1_context * ctx , void (* fun )(const char * message , void * data ), const void * data ) {
183
- ARG_CHECK_NO_RETURN (ctx != secp256k1_context_static );
196
+ /* We compare pointers instead of checking secp256k1_context_is_proper() here
197
+ because setting callbacks is allowed on *copies* of the static context:
198
+ it's harmless and makes testing easier. */
199
+ ARG_CHECK_VOID (ctx != secp256k1_context_static );
184
200
if (fun == NULL ) {
185
201
fun = secp256k1_default_error_callback_fn ;
186
202
}
0 commit comments