Skip to content

Commit

Permalink
Use p==NULL not !p (in if statements, mainly)
Browse files Browse the repository at this point in the history
Reviewed-by: Tim Hudson <[email protected]>
  • Loading branch information
richsalz authored and Rich Salz committed May 11, 2015
1 parent 344c271 commit 75ebbd9
Show file tree
Hide file tree
Showing 118 changed files with 754 additions and 724 deletions.
5 changes: 3 additions & 2 deletions apps/apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,12 @@ int add_oid_section(CONF *conf)
STACK_OF(CONF_VALUE) *sktmp;
CONF_VALUE *cnf;
int i;
if (!(p = NCONF_get_string(conf, NULL, "oid_section"))) {

if ((p = NCONF_get_string(conf, NULL, "oid_section")) == NULL) {
ERR_clear_error();
return 1;
}
if (!(sktmp = NCONF_get_section(conf, p))) {
if ((sktmp = NCONF_get_section(conf, p)) == NULL) {
BIO_printf(bio_err, "problem loading oid section %s\n", p);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
* Its best to dup the subject DN and then delete any email addresses
* because this retains its structure.
*/
if (!(dn_subject = X509_NAME_dup(subject))) {
if ((dn_subject = X509_NAME_dup(subject)) == NULL) {
BIO_printf(bio_err, "Memory allocation failure\n");
goto end;
}
Expand Down
22 changes: 11 additions & 11 deletions apps/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ int cms_main(int argc, char **argv)
if ((encerts = sk_X509_new_null()) == NULL)
goto end;
while (*argv) {
if (!(cert = load_cert(*argv, FORMAT_PEM,
NULL, e, "recipient certificate file")))
if ((cert = load_cert(*argv, FORMAT_PEM, NULL, e,
"recipient certificate file")) == NULL)
goto end;
sk_X509_push(encerts, cert);
cert = NULL;
Expand All @@ -727,24 +727,24 @@ int cms_main(int argc, char **argv)
}

if (certfile) {
if (!(other = load_certs(certfile, FORMAT_PEM, NULL,
e, "certificate file"))) {
if ((other = load_certs(certfile, FORMAT_PEM, NULL, e,
"certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
}

if (recipfile && (operation == SMIME_DECRYPT)) {
if (!(recip = load_cert(recipfile, FORMAT_PEM, NULL,
e, "recipient certificate file"))) {
if ((recip = load_cert(recipfile, FORMAT_PEM, NULL, e,
"recipient certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
}

if (operation == SMIME_SIGN_RECEIPT) {
if (!(signer = load_cert(signerfile, FORMAT_PEM, NULL,
e, "receipt signer certificate file"))) {
if ((signer = load_cert(signerfile, FORMAT_PEM, NULL, e,
"receipt signer certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
Expand Down Expand Up @@ -787,7 +787,7 @@ int cms_main(int argc, char **argv)
}
if (contfile) {
BIO_free(indata);
if (!(indata = BIO_new_file(contfile, "rb"))) {
if ((indata = BIO_new_file(contfile, "rb")) == NULL) {
BIO_printf(bio_err, "Can't read content file %s\n", contfile);
goto end;
}
Expand All @@ -807,7 +807,7 @@ int cms_main(int argc, char **argv)

if (rctfile) {
char *rctmode = (rctformat == FORMAT_ASN1) ? "rb" : "r";
if (!(rctin = BIO_new_file(rctfile, rctmode))) {
if ((rctin = BIO_new_file(rctfile, rctmode)) == NULL) {
BIO_printf(bio_err, "Can't open receipt file %s\n", rctfile);
goto end;
}
Expand All @@ -834,7 +834,7 @@ int cms_main(int argc, char **argv)
goto end;

if ((operation == SMIME_VERIFY) || (operation == SMIME_VERIFY_RECEIPT)) {
if (!(store = setup_verify(CAfile, CApath)))
if ((store = setup_verify(CAfile, CApath)) == NULL)
goto end;
X509_STORE_set_verify_cb(store, cms_cb);
if (vpmtouched)
Expand Down
2 changes: 1 addition & 1 deletion apps/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int crl_main(int argc, char **argv)
goto end;

if (do_ver) {
if (!(store = setup_verify(CAfile, CApath)))
if ((store = setup_verify(CAfile, CApath)) == NULL)
goto end;
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
if (lookup == NULL)
Expand Down
3 changes: 2 additions & 1 deletion apps/crl2p7.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ int crl2pkcs7_main(int argc, char **argv)
nocrl = 1;
break;
case OPT_CERTFILE:
if (!certflst && !(certflst = sk_OPENSSL_STRING_new_null()))
if ((certflst == NULL)
&& (certflst = sk_OPENSSL_STRING_new_null()) == NULL)
goto end;
if (!sk_OPENSSL_STRING_push(certflst, *(++argv))) {
sk_OPENSSL_STRING_free(certflst);
Expand Down
18 changes: 9 additions & 9 deletions apps/pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ int pkcs12_main(int argc, char **argv)
/* Add any more certificates asked for */
if (certfile) {
STACK_OF(X509) *morecerts = NULL;
if (!(morecerts = load_certs(certfile, FORMAT_PEM, NULL, e,
"certificates from certfile")))
if ((morecerts = load_certs(certfile, FORMAT_PEM, NULL, e,
"certificates from certfile")) == NULL)
goto export_end;
while (sk_X509_num(morecerts) > 0)
sk_X509_push(certs, sk_X509_shift(morecerts));
Expand All @@ -434,7 +434,7 @@ int pkcs12_main(int argc, char **argv)
int vret;
STACK_OF(X509) *chain2;
X509_STORE *store;
if (!(store = setup_verify(CAfile, CApath)))
if ((store = setup_verify(CAfile, CApath)) == NULL)
goto export_end;

vret = get_cert_chain(ucert, store, &chain2);
Expand Down Expand Up @@ -511,7 +511,7 @@ int pkcs12_main(int argc, char **argv)

}

if (!(p12 = d2i_PKCS12_bio(in, NULL))) {
if ((p12 = d2i_PKCS12_bio(in, NULL)) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
Expand Down Expand Up @@ -570,7 +570,7 @@ int dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass,
int ret = 0;
PKCS7 *p7;

if (!(asafes = PKCS12_unpack_authsafes(p12)))
if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL)
return 0;
for (i = 0; i < sk_PKCS7_num(asafes); i++) {
p7 = sk_PKCS7_value(asafes, i);
Expand Down Expand Up @@ -634,7 +634,7 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass,
return 1;
print_attribs(out, bag->attrib, "Bag Attributes");
p8 = bag->value.keybag;
if (!(pkey = EVP_PKCS82PKEY(p8)))
if ((pkey = EVP_PKCS82PKEY(p8)) == NULL)
return 0;
print_attribs(out, p8->attributes, "Key Attributes");
PEM_write_bio_PrivateKey(out, pkey, enc, NULL, 0, NULL, pempass);
Expand All @@ -649,9 +649,9 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass,
if (options & NOKEYS)
return 1;
print_attribs(out, bag->attrib, "Bag Attributes");
if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen)))
if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL)
return 0;
if (!(pkey = EVP_PKCS82PKEY(p8))) {
if ((pkey = EVP_PKCS82PKEY(p8)) == NULL) {
PKCS8_PRIV_KEY_INFO_free(p8);
return 0;
}
Expand All @@ -674,7 +674,7 @@ int dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass,
print_attribs(out, bag->attrib, "Bag Attributes");
if (M_PKCS12_cert_bag_type(bag) != NID_x509Certificate)
return 1;
if (!(x509 = PKCS12_certbag2x509(bag)))
if ((x509 = PKCS12_certbag2x509(bag)) == NULL)
return 0;
dump_cert_text(out, x509);
PEM_write_bio_X509(out, x509);
Expand Down
10 changes: 5 additions & 5 deletions apps/pkcs8.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int pkcs8_main(int argc, char **argv)
pkey = load_key(infile, informat, 1, passin, e, "key");
if (!pkey)
goto end;
if (!(p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken))) {
if ((p8inf = EVP_PKEY2PKCS8_broken(pkey, p8_broken)) == NULL) {
BIO_printf(bio_err, "Error converting key\n");
ERR_print_errors(bio_err);
goto end;
Expand All @@ -235,9 +235,9 @@ int pkcs8_main(int argc, char **argv)
goto end;
}
app_RAND_load_file(NULL, 0);
if (!(p8 = PKCS8_encrypt(pbe_nid, cipher,
p8pass, strlen(p8pass),
NULL, 0, iter, p8inf))) {
if ((p8 = PKCS8_encrypt(pbe_nid, cipher,
p8pass, strlen(p8pass),
NULL, 0, iter, p8inf)) == NULL) {
BIO_printf(bio_err, "Error encrypting key\n");
ERR_print_errors(bio_err);
goto end;
Expand Down Expand Up @@ -296,7 +296,7 @@ int pkcs8_main(int argc, char **argv)
goto end;
}

if (!(pkey = EVP_PKCS82PKEY(p8inf))) {
if ((pkey = EVP_PKCS82PKEY(p8inf)) == NULL) {
BIO_printf(bio_err, "Error converting key\n");
ERR_print_errors(bio_err);
goto end;
Expand Down
2 changes: 1 addition & 1 deletion apps/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ static int build_subject(X509_REQ *req, char *subject, unsigned long chtype,
{
X509_NAME *n;

if (!(n = parse_name(subject, chtype, multirdn)))
if ((n = parse_name(subject, chtype, multirdn)) == NULL)
return 0;

if (!X509_REQ_set_subject_name(req, n)) {
Expand Down
3 changes: 2 additions & 1 deletion apps/s_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ static int ssl_srp_verify_param_cb(SSL *s, void *arg)
{
SRP_ARG *srp_arg = (SRP_ARG *)arg;
BIGNUM *N = NULL, *g = NULL;
if (!(N = SSL_get_srp_N(s)) || !(g = SSL_get_srp_g(s)))

if (((N = SSL_get_srp_N(s)) == NULL) || ((g = SSL_get_srp_g(s)) == NULL))
return 0;
if (srp_arg->debug || srp_arg->msg || srp_arg->amp == 1) {
BIO_printf(bio_err, "SRP parameters:\n");
Expand Down
12 changes: 6 additions & 6 deletions apps/smime.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,16 @@ int smime_main(int argc, char **argv)
}

if (certfile) {
if (!(other = load_certs(certfile, FORMAT_PEM, NULL,
e, "certificate file"))) {
if ((other = load_certs(certfile, FORMAT_PEM, NULL,
e, "certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
}

if (recipfile && (operation == SMIME_DECRYPT)) {
if (!(recip = load_cert(recipfile, FORMAT_PEM, NULL,
e, "recipient certificate file"))) {
if ((recip = load_cert(recipfile, FORMAT_PEM, NULL,
e, "recipient certificate file")) == NULL) {
ERR_print_errors(bio_err);
goto end;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ int smime_main(int argc, char **argv)
}
if (contfile) {
BIO_free(indata);
if (!(indata = BIO_new_file(contfile, "rb"))) {
if ((indata = BIO_new_file(contfile, "rb")) == NULL) {
BIO_printf(bio_err, "Can't read content file %s\n", contfile);
goto end;
}
Expand All @@ -527,7 +527,7 @@ int smime_main(int argc, char **argv)
goto end;

if (operation == SMIME_VERIFY) {
if (!(store = setup_verify(CAfile, CApath)))
if ((store = setup_verify(CAfile, CApath)) == NULL)
goto end;
X509_STORE_set_verify_cb(store, smime_cb);
if (vpmtouched)
Expand Down
27 changes: 16 additions & 11 deletions apps/srp.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,13 @@ int srp_main(int argc, char **argv)
row[DB_srptype] = BUF_strdup("v");
row[DB_srpgN] = BUF_strdup(gNid);

if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
|| !row[DB_srpverifier] || !row[DB_srpsalt]
|| (userinfo &&
(!(row [DB_srpinfo] = BUF_strdup (userinfo))))
if ((row[DB_srpid] == NULL)
|| (row[DB_srpgN] == NULL)
|| (row[DB_srptype] == NULL)
|| (row[DB_srpverifier] == NULL)
|| (row[DB_srpsalt] == NULL)
|| (userinfo
&& ((row[DB_srpinfo] = BUF_strdup(userinfo)) == NULL))
|| !update_index(db, row)) {
OPENSSL_free(row[DB_srpid]);
OPENSSL_free(row[DB_srpgN]);
Expand Down Expand Up @@ -596,10 +599,14 @@ int srp_main(int argc, char **argv)
row[DB_srptype][0] = 'v';
row[DB_srpgN] = BUF_strdup(gNid);

if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
|| !row[DB_srpverifier] || !row[DB_srpsalt]
if (row[DB_srpid] == NULL
|| row[DB_srpgN] == NULL
|| row[DB_srptype] == NULL
|| row[DB_srpverifier] == NULL
|| row[DB_srpsalt] == NULL
|| (userinfo
&& (!(row[DB_srpinfo] = BUF_strdup(userinfo)))))
&& ((row[DB_srpinfo] = BUF_strdup(userinfo))
== NULL)))
goto end;

doupdatedb = 1;
Expand All @@ -612,12 +619,10 @@ int srp_main(int argc, char **argv)
user);
errors++;
} else {
char **xpp =
sk_OPENSSL_PSTRING_value(db->db->data, userindex);
BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);

BIO_printf(bio_err, "user \"%s\" revoked. t\n", user);
xpp[DB_srptype][0] = 'R';

doupdatedb = 1;
}
}
Expand Down
Loading

0 comments on commit 75ebbd9

Please sign in to comment.