Skip to content

Commit 1f41437

Browse files
committed
Merge pull request bitcoin#316
2b199de Use the explicit NULL macro for pointer comparisons. (Gregory Maxwell)
2 parents fe0d463 + 2b199de commit 1f41437

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/bench.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), v
3737
double max = 0.0;
3838
for (i = 0; i < count; i++) {
3939
double begin, total;
40-
if (setup) {
40+
if (setup != NULL) {
4141
setup(data);
4242
}
4343
begin = gettimedouble();
4444
benchmark(data);
4545
total = gettimedouble() - begin;
46-
if (teardown) {
46+
if (teardown != NULL) {
4747
teardown(data);
4848
}
4949
if (total < min) {

src/ecmult_gen_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
159159
secp256k1_rfc6979_hmac_sha256_t rng;
160160
int retry;
161161
unsigned char keydata[64] = {0};
162-
if (!seed32) {
162+
if (seed32 == NULL) {
163163
/* When seed is NULL, reset the initial point and blinding value. */
164164
secp256k1_gej_set_ge(&ctx->initial, &secp256k1_ge_const_g);
165165
secp256k1_gej_neg(&ctx->initial, &ctx->initial);
@@ -172,7 +172,7 @@ static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const
172172
* asking the caller for blinding values directly and expecting them to retry on failure.
173173
*/
174174
memcpy(keydata, nonce32, 32);
175-
if (seed32) {
175+
if (seed32 != NULL) {
176176
memcpy(keydata + 32, seed32, 32);
177177
}
178178
secp256k1_rfc6979_hmac_sha256_initialize(&rng, keydata, seed32 ? 64 : 32);

src/group_impl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,13 @@ static void secp256k1_gej_double_var(secp256k1_gej *r, const secp256k1_gej *a, s
265265
*/
266266
r->infinity = a->infinity;
267267
if (r->infinity) {
268-
if (rzr) {
268+
if (rzr != NULL) {
269269
secp256k1_fe_set_int(rzr, 1);
270270
}
271271
return;
272272
}
273273

274-
if (rzr) {
274+
if (rzr != NULL) {
275275
*rzr = a->y;
276276
secp256k1_fe_normalize_weak(rzr);
277277
secp256k1_fe_mul_int(rzr, 2);
@@ -315,7 +315,7 @@ static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, cons
315315
}
316316

317317
if (b->infinity) {
318-
if (rzr) {
318+
if (rzr != NULL) {
319319
secp256k1_fe_set_int(rzr, 1);
320320
}
321321
*r = *a;
@@ -335,7 +335,7 @@ static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, cons
335335
if (secp256k1_fe_normalizes_to_zero_var(&i)) {
336336
secp256k1_gej_double_var(r, a, rzr);
337337
} else {
338-
if (rzr) {
338+
if (rzr != NULL) {
339339
secp256k1_fe_set_int(rzr, 0);
340340
}
341341
r->infinity = 1;
@@ -346,7 +346,7 @@ static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, cons
346346
secp256k1_fe_sqr(&h2, &h);
347347
secp256k1_fe_mul(&h3, &h, &h2);
348348
secp256k1_fe_mul(&h, &h, &b->z);
349-
if (rzr) {
349+
if (rzr != NULL) {
350350
*rzr = h;
351351
}
352352
secp256k1_fe_mul(&r->z, &a->z, &h);
@@ -366,7 +366,7 @@ static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, c
366366
return;
367367
}
368368
if (b->infinity) {
369-
if (rzr) {
369+
if (rzr != NULL) {
370370
secp256k1_fe_set_int(rzr, 1);
371371
}
372372
*r = *a;
@@ -385,7 +385,7 @@ static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, c
385385
if (secp256k1_fe_normalizes_to_zero_var(&i)) {
386386
secp256k1_gej_double_var(r, a, rzr);
387387
} else {
388-
if (rzr) {
388+
if (rzr != NULL) {
389389
secp256k1_fe_set_int(rzr, 0);
390390
}
391391
r->infinity = 1;
@@ -395,7 +395,7 @@ static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, c
395395
secp256k1_fe_sqr(&i2, &i);
396396
secp256k1_fe_sqr(&h2, &h);
397397
secp256k1_fe_mul(&h3, &h, &h2);
398-
if (rzr) {
398+
if (rzr != NULL) {
399399
*rzr = h;
400400
}
401401
secp256k1_fe_mul(&r->z, &a->z, &h);

src/modules/schnorr/schnorr_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static int secp256k1_schnorr_sig_sign(const secp256k1_ecmult_gen_context* ctx, u
7373
n = *nonce;
7474

7575
secp256k1_ecmult_gen(ctx, &Rj, &n);
76-
if (pubnonce) {
76+
if (pubnonce != NULL) {
7777
secp256k1_gej_add_ge(&Rj, &Rj, pubnonce);
7878
}
7979
secp256k1_ge_set_gej(&Ra, &Rj);

src/secp256k1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ secp256k1_context* secp256k1_context_clone(const secp256k1_context* ctx) {
8585
}
8686

8787
void secp256k1_context_destroy(secp256k1_context* ctx) {
88-
if (ctx) {
88+
if (ctx != NULL) {
8989
secp256k1_ecmult_context_clear(&ctx->ecmult_ctx);
9090
secp256k1_ecmult_gen_context_clear(&ctx->ecmult_gen_ctx);
9191

@@ -94,15 +94,15 @@ void secp256k1_context_destroy(secp256k1_context* ctx) {
9494
}
9595

9696
void secp256k1_context_set_illegal_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
97-
if (!fun) {
97+
if (fun == NULL) {
9898
fun = default_illegal_callback_fn;
9999
}
100100
ctx->illegal_callback.fn = fun;
101101
ctx->illegal_callback.data = data;
102102
}
103103

104104
void secp256k1_context_set_error_callback(secp256k1_context* ctx, void (*fun)(const char* message, void* data), const void* data) {
105-
if (!fun) {
105+
if (fun == NULL) {
106106
fun = default_error_callback_fn;
107107
}
108108
ctx->error_callback.fn = fun;

src/tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ void test_ecdsa_openssl(void) {
21982198
secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &qj, &key);
21992199
secp256k1_ge_set_gej(&q, &qj);
22002200
ec_key = get_openssl_key(&key);
2201-
CHECK(ec_key);
2201+
CHECK(ec_key != NULL);
22022202
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
22032203
CHECK(secp256k1_ecdsa_sig_parse(&sigr, &sigs, signature, sigsize));
22042204
CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sigr, &sigs, &q, &msg));
@@ -2257,7 +2257,7 @@ int main(int argc, char **argv) {
22572257
}
22582258
} else {
22592259
FILE *frand = fopen("/dev/urandom", "r");
2260-
if (!frand || !fread(&seed16, sizeof(seed16), 1, frand)) {
2260+
if ((frand == NULL) || !fread(&seed16, sizeof(seed16), 1, frand)) {
22612261
uint64_t t = time(NULL) * (uint64_t)1337;
22622262
seed16[0] ^= t;
22632263
seed16[1] ^= t >> 8;

0 commit comments

Comments
 (0)