refactor: remove unnecessary malloc result casts

It seems that there is no good reason to do this and it's even
considered bad practice, see e.g. https://stackoverflow.com/a/605858

This commit touches mostly test code, the only two functions used
in production are `secp256k1_context_{create,clone}`.

Instances were found manually via `$ git grep "malloc("`
This commit is contained in:
Sebastian Falbesoner
2026-01-30 15:58:30 +01:00
parent 57315a6985
commit 97b3c47849
3 changed files with 17 additions and 17 deletions

View File

@@ -51,18 +51,18 @@ static void run_schnorrsig_bench(int iters, int argc, char** argv) {
int d = argc == 1;
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
data.keypairs = (const secp256k1_keypair **)malloc(iters * sizeof(secp256k1_keypair *));
data.pk = (const unsigned char **)malloc(iters * sizeof(unsigned char *));
data.msgs = (const unsigned char **)malloc(iters * sizeof(unsigned char *));
data.sigs = (const unsigned char **)malloc(iters * sizeof(unsigned char *));
data.keypairs = malloc(iters * sizeof(secp256k1_keypair *));
data.pk = malloc(iters * sizeof(unsigned char *));
data.msgs = malloc(iters * sizeof(unsigned char *));
data.sigs = malloc(iters * sizeof(unsigned char *));
CHECK(MSGLEN >= 4);
for (i = 0; i < iters; i++) {
unsigned char sk[32];
unsigned char *msg = (unsigned char *)malloc(MSGLEN);
unsigned char *sig = (unsigned char *)malloc(64);
secp256k1_keypair *keypair = (secp256k1_keypair *)malloc(sizeof(*keypair));
unsigned char *pk_char = (unsigned char *)malloc(32);
unsigned char *msg = malloc(MSGLEN);
unsigned char *sig = malloc(64);
secp256k1_keypair *keypair = malloc(sizeof(*keypair));
unsigned char *pk_char = malloc(32);
secp256k1_xonly_pubkey pk;
msg[0] = sk[0] = i;
msg[1] = sk[1] = i >> 8;