Skip to content

Commit 792d7c4

Browse files
Don't use string literals for char arrays without NUL termination
unsigned char foo[4] = "abcd" is not valid C++ because the string literal "abcd" does not fit into foo due to the terminating NUL character. This is valid in C, it will just omit the NUL character. Fixes #962.
1 parent 2cc3cfa commit 792d7c4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/secp256k1_schnorrsig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct {
8585
void* ndata;
8686
} secp256k1_schnorrsig_extraparams;
8787

88-
#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC "\xda\x6f\xb3\x8c"
88+
#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC { '\xda', '\x6f', '\xb3', '\x8c' }
8989
#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT {\
9090
SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC,\
9191
NULL,\

src/modules/schnorrsig/main_impl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static void secp256k1_nonce_function_bip340_sha256_tagged_aux(secp256k1_sha256 *
4747
* by using the correct tagged hash function. */
4848
static const unsigned char bip340_algo[13] = "BIP0340/nonce";
4949

50+
static const unsigned char schnorrsig_extraparams_magic[4] = SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC;
51+
5052
static int nonce_function_bip340(unsigned char *nonce32, const unsigned char *msg, size_t msglen, const unsigned char *key32, const unsigned char *xonly_pk32, const unsigned char *algo, size_t algolen, void *data) {
5153
secp256k1_sha256 sha;
5254
unsigned char masked_key[32];
@@ -194,7 +196,7 @@ int secp256k1_schnorrsig_sign_custom(const secp256k1_context* ctx, unsigned char
194196

195197
if (extraparams != NULL) {
196198
ARG_CHECK(secp256k1_memcmp_var(extraparams->magic,
197-
SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC,
199+
schnorrsig_extraparams_magic,
198200
sizeof(extraparams->magic)) == 0);
199201
noncefp = extraparams->noncefp;
200202
ndata = extraparams->ndata;

0 commit comments

Comments
 (0)