29
29
30
30
static int count = 64 ;
31
31
static secp256k1_context * ctx = NULL ;
32
+ static secp256k1_context * sttc = NULL ;
32
33
33
34
static void counting_illegal_callback_fn (const char * str , void * data ) {
34
35
/* Dummy callback function that just counts. */
@@ -180,9 +181,7 @@ void run_context_tests(int use_prealloc) {
180
181
unsigned char ctmp [32 ];
181
182
int32_t ecount ;
182
183
int32_t ecount2 ;
183
- secp256k1_context * sttc ;
184
184
void * ctx_prealloc = NULL ;
185
- void * sttc_prealloc = NULL ;
186
185
187
186
secp256k1_gej pubj ;
188
187
secp256k1_ge pub ;
@@ -196,11 +195,7 @@ void run_context_tests(int use_prealloc) {
196
195
ctx_prealloc = malloc (secp256k1_context_preallocated_size (SECP256K1_CONTEXT_NONE ));
197
196
CHECK (ctx_prealloc != NULL );
198
197
ctx = secp256k1_context_preallocated_create (ctx_prealloc , SECP256K1_CONTEXT_NONE );
199
- sttc_prealloc = malloc (secp256k1_context_preallocated_clone_size (secp256k1_context_static ));
200
- CHECK (sttc_prealloc != NULL );
201
- sttc = secp256k1_context_preallocated_clone (secp256k1_context_static , sttc_prealloc );
202
198
} else {
203
- sttc = secp256k1_context_clone (secp256k1_context_static );
204
199
ctx = secp256k1_context_create (SECP256K1_CONTEXT_NONE );
205
200
}
206
201
@@ -312,12 +307,9 @@ void run_context_tests(int use_prealloc) {
312
307
/* cleanup */
313
308
if (use_prealloc ) {
314
309
secp256k1_context_preallocated_destroy (ctx );
315
- secp256k1_context_preallocated_destroy (sttc );
316
310
free (ctx_prealloc );
317
- free (sttc_prealloc );
318
311
} else {
319
312
secp256k1_context_destroy (ctx );
320
- secp256k1_context_destroy (sttc );
321
313
}
322
314
/* Defined as no-op. */
323
315
secp256k1_context_destroy (NULL );
@@ -7357,6 +7349,15 @@ int main(int argc, char **argv) {
7357
7349
secp256k1_testrand_init (argc > 2 ? argv [2 ] : NULL );
7358
7350
7359
7351
/* initialize */
7352
+ /* Make a writable copy of secp256k1_context_static in order to test the effect of API functions
7353
+ that write to the context. The API does not support cloning the static context, so we use
7354
+ memcpy instead. The user is not supposed to copy a context but we should still ensure that
7355
+ the API functions handle copies of the static context gracefully. */
7356
+ sttc = malloc (sizeof (* secp256k1_context_static ));
7357
+ CHECK (sttc != NULL );
7358
+ memcpy (sttc , secp256k1_context_static , sizeof (secp256k1_context ));
7359
+ CHECK (!secp256k1_context_is_proper (sttc ));
7360
+
7360
7361
run_selftest_tests ();
7361
7362
run_context_tests (0 );
7362
7363
run_context_tests (1 );
@@ -7463,6 +7464,7 @@ int main(int argc, char **argv) {
7463
7464
secp256k1_testrand_finish ();
7464
7465
7465
7466
/* shutdown */
7467
+ free (sttc );
7466
7468
secp256k1_context_destroy (ctx );
7467
7469
7468
7470
printf ("no problems found\n" );
0 commit comments