From 90945fa31a42dcf3beb90540c618e4d627c595ea Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 30 Oct 2015 11:12:26 +0000 Subject: Continue standardising malloc style for libcrypto Continuing from previous commit ensure our style is consistent for malloc return checks. Reviewed-by: Kurt Roeckx --- crypto/asn1/a_mbstr.c | 2 +- crypto/asn1/a_object.c | 8 ++++---- crypto/asn1/a_strex.c | 2 +- crypto/asn1/a_strnid.c | 6 +++--- crypto/asn1/ameth_lib.c | 6 +++--- crypto/asn1/asn1_gen.c | 2 +- crypto/asn1/asn1_lib.c | 2 +- crypto/asn1/asn_mime.c | 10 +++++----- crypto/asn1/bio_asn1.c | 4 ++-- crypto/asn1/bio_ndef.c | 6 +++--- crypto/asn1/p5_pbe.c | 4 ++-- crypto/asn1/p5_pbev2.c | 4 ++-- crypto/asn1/p5_scrypt.c | 2 +- crypto/asn1/p8_pkey.c | 2 +- crypto/asn1/tasn_dec.c | 2 +- crypto/asn1/tasn_enc.c | 6 +++--- crypto/asn1/tasn_new.c | 6 +++--- crypto/asn1/tasn_utl.c | 2 +- crypto/asn1/x_bignum.c | 4 ++-- crypto/asn1/x_pkey.c | 4 ++-- crypto/asn1/x_pubkey.c | 4 ++-- 21 files changed, 44 insertions(+), 44 deletions(-) (limited to 'crypto/asn1') diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c index 46100c32cb..0892976293 100644 --- a/crypto/asn1/a_mbstr.c +++ b/crypto/asn1/a_mbstr.c @@ -200,7 +200,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, } else { free_out = 1; dest = ASN1_STRING_type_new(str_type); - if (!dest) { + if (dest == NULL) { ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); return -1; } diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c index 80b5055978..cabda53519 100644 --- a/crypto/asn1/a_object.c +++ b/crypto/asn1/a_object.c @@ -139,9 +139,9 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) } if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { use_bn = 1; - if (!bl) + if (bl == NULL) bl = BN_new(); - if (!bl || !BN_set_word(bl, l)) + if (bl == NULL || !BN_set_word(bl, l)) goto err; } if (use_bn) { @@ -173,7 +173,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) OPENSSL_free(tmp); tmpsize = blsize + 32; tmp = OPENSSL_malloc(tmpsize); - if (!tmp) + if (tmp == NULL) goto err; } while (blsize--) @@ -225,7 +225,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) i = i2t_ASN1_OBJECT(buf, sizeof buf, a); if (i > (int)(sizeof(buf) - 1)) { p = OPENSSL_malloc(i + 1); - if (!p) + if (p == NULL) return -1; i2t_ASN1_OBJECT(p, i + 1, a); } diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c index c9d3cea036..7d37c73d39 100644 --- a/crypto/asn1/a_strex.c +++ b/crypto/asn1/a_strex.c @@ -305,7 +305,7 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, t.value.ptr = (char *)str; der_len = i2d_ASN1_TYPE(&t, NULL); der_buf = OPENSSL_malloc(der_len); - if (!der_buf) + if (der_buf == NULL) return -1; p = der_buf; i2d_ASN1_TYPE(&t, &p); diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index 1c6bbd4061..43252c1cf4 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -235,16 +235,16 @@ static ASN1_STRING_TABLE *stable_get(int nid) { ASN1_STRING_TABLE *tmp, *rv; /* Always need a string table so allocate one if NULL */ - if (!stable) { + if (stable == NULL) { stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); - if (!stable) + if (stable == NULL) return NULL; } tmp = ASN1_STRING_TABLE_get(nid); if (tmp && tmp->flags & STABLE_FLAGS_MALLOC) return tmp; rv = OPENSSL_malloc(sizeof(*rv)); - if (!rv) + if (rv == NULL) return NULL; if (!sk_ASN1_STRING_TABLE_push(stable, rv)) { OPENSSL_free(rv); diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index 2deb67917b..05f0a80da8 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -224,7 +224,7 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { if (app_methods == NULL) { app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); - if (!app_methods) + if (app_methods == NULL) return 0; } if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) @@ -237,7 +237,7 @@ int EVP_PKEY_asn1_add_alias(int to, int from) { EVP_PKEY_ASN1_METHOD *ameth; ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL); - if (!ameth) + if (ameth == NULL) return 0; ameth->pkey_base_id = to; if (!EVP_PKEY_asn1_add0(ameth)) { @@ -277,7 +277,7 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, { EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth)); - if (!ameth) + if (ameth == NULL) return NULL; ameth->pkey_id = id; diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 5f01b8dac1..200d88d1b2 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -243,7 +243,7 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth, /* Allocate buffer for new encoding */ new_der = OPENSSL_malloc(len); - if (!new_der) + if (new_der == NULL) goto err; /* Generate tagged encoding */ diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index ef9223c485..56fd9bf4c3 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -296,7 +296,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) if (!str) return NULL; ret = ASN1_STRING_new(); - if (!ret) + if (ret == NULL) return NULL; if (!ASN1_STRING_copy(ret, str)) { ASN1_STRING_free(ret); diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 2a227be5c5..12f6fd67af 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -149,7 +149,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, BIO *b64; int r; b64 = BIO_new(BIO_f_base64()); - if (!b64) { + if (b64 == NULL) { ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE); return 0; } @@ -533,7 +533,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) * when streaming as we don't end up with one OCTET STRING per line. */ bf = BIO_new(BIO_f_buffer()); - if (!bf) + if (bf == NULL) return 0; out = BIO_push(bf, out); if (flags & SMIME_BINARY) { @@ -678,7 +678,7 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) int len, state, save_state = 0; headers = sk_MIME_HEADER_new(mime_hdr_cmp); - if (!headers) + if (headers == NULL) return NULL; while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { /* If whitespace at line start then continuation line */ @@ -850,7 +850,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } mhdr = OPENSSL_malloc(sizeof(*mhdr)); - if (!mhdr) + if (mhdr == NULL) goto err; mhdr->name = tmpname; mhdr->value = tmpval; @@ -889,7 +889,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) } /* Parameter values are case sensitive so leave as is */ mparam = OPENSSL_malloc(sizeof(*mparam)); - if (!mparam) + if (mparam == NULL) goto err; mparam->param_name = tmpname; mparam->param_value = tmpval; diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c index 910d06f04d..a5bcc265fd 100644 --- a/crypto/asn1/bio_asn1.c +++ b/crypto/asn1/bio_asn1.c @@ -147,7 +147,7 @@ static int asn1_bio_new(BIO *b) { BIO_ASN1_BUF_CTX *ctx; ctx = OPENSSL_malloc(sizeof(*ctx)); - if (!ctx) + if (ctx == NULL) return 0; if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { OPENSSL_free(ctx); @@ -162,7 +162,7 @@ static int asn1_bio_new(BIO *b) static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) { ctx->buf = OPENSSL_malloc(size); - if (!ctx->buf) + if (ctx->buf == NULL) return 0; ctx->bufsize = size; ctx->bufpos = 0; diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c index ff2fdf529b..dfbbc68986 100644 --- a/crypto/asn1/bio_ndef.c +++ b/crypto/asn1/bio_ndef.c @@ -113,7 +113,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it) out = BIO_push(asn_bio, out); - if (!ndef_aux || !asn_bio || !out) + if (ndef_aux == NULL || asn_bio == NULL || !out) goto err; BIO_asn1_set_prefix(asn_bio, ndef_prefix, ndef_prefix_free); @@ -160,7 +160,7 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); p = OPENSSL_malloc(derlen); - if (!p) + if (p == NULL) return 0; ndef_aux->derbuf = p; @@ -229,7 +229,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); p = OPENSSL_malloc(derlen); - if (!p) + if (p == NULL) return 0; ndef_aux->derbuf = p; diff --git a/crypto/asn1/p5_pbe.c b/crypto/asn1/p5_pbe.c index cc91fad53b..4d7a9c61c1 100644 --- a/crypto/asn1/p5_pbe.c +++ b/crypto/asn1/p5_pbe.c @@ -82,7 +82,7 @@ int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, unsigned char *sstr; pbe = PBEPARAM_new(); - if (!pbe) { + if (pbe == NULL) { ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); goto err; } @@ -128,7 +128,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, { X509_ALGOR *ret; ret = X509_ALGOR_new(); - if (!ret) { + if (ret == NULL) { ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE); return NULL; } diff --git a/crypto/asn1/p5_pbev2.c b/crypto/asn1/p5_pbev2.c index 23ed232dd3..ba0c92aca8 100644 --- a/crypto/asn1/p5_pbev2.c +++ b/crypto/asn1/p5_pbev2.c @@ -242,7 +242,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* prf can stay NULL if we are using hmacWithSHA1 */ if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { kdf->prf = X509_ALGOR_new(); - if (!kdf->prf) + if (kdf->prf == NULL) goto merr; X509_ALGOR_set0(kdf->prf, OBJ_nid2obj(prf_nid), V_ASN1_NULL, NULL); } @@ -250,7 +250,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, /* Finally setup the keyfunc structure */ keyfunc = X509_ALGOR_new(); - if (!keyfunc) + if (keyfunc == NULL) goto merr; keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); diff --git a/crypto/asn1/p5_scrypt.c b/crypto/asn1/p5_scrypt.c index 3667546634..06bb2ac2c2 100644 --- a/crypto/asn1/p5_scrypt.c +++ b/crypto/asn1/p5_scrypt.c @@ -247,7 +247,7 @@ static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen, /* Finally setup the keyfunc structure */ keyfunc = X509_ALGOR_new(); - if (!keyfunc) + if (keyfunc == NULL) goto merr; keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt); diff --git a/crypto/asn1/p8_pkey.c b/crypto/asn1/p8_pkey.c index ff55a5bdb0..f4fbc085e7 100644 --- a/crypto/asn1/p8_pkey.c +++ b/crypto/asn1/p8_pkey.c @@ -99,7 +99,7 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int pmtype; ASN1_OCTET_STRING *oct; oct = ASN1_OCTET_STRING_new(); - if (!oct) + if (oct == NULL) return 0; oct->data = penc; ppenc = &oct->data; diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index 94445bdc49..595c5e4cb1 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -893,7 +893,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, /* All based on ASN1_STRING and handled the same */ if (!*pval) { stmp = ASN1_STRING_type_new(utype); - if (!stmp) { + if (stmp == NULL) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; } diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c index e2feee0ec3..50375225b0 100644 --- a/crypto/asn1/tasn_enc.c +++ b/crypto/asn1/tasn_enc.c @@ -111,7 +111,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, if (len <= 0) return len; buf = OPENSSL_malloc(len); - if (!buf) + if (buf == NULL) return -1; p = buf; ASN1_item_ex_i2d(&val, &p, it, -1, flags); @@ -423,10 +423,10 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, else { derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst)); - if (!derlst) + if (derlst == NULL) return 0; tmpdat = OPENSSL_malloc(skcontlen); - if (!tmpdat) { + if (tmpdat == NULL) { OPENSSL_free(derlst); return 0; } diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c index 6a2ad62d70..668f6419d1 100644 --- a/crypto/asn1/tasn_new.c +++ b/crypto/asn1/tasn_new.c @@ -147,7 +147,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) memset(*pval, 0, it->size); } else { *pval = OPENSSL_zalloc(it->size); - if (!*pval) + if (*pval == NULL) goto memerr; } asn1_set_choice_selector(pval, -1, it); @@ -173,7 +173,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed) memset(*pval, 0, it->size); } else { *pval = OPENSSL_zalloc(it->size); - if (!*pval) + if (*pval == NULL) goto memerr; } asn1_do_lock(pval, 0, it); @@ -341,7 +341,7 @@ static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it, case V_ASN1_ANY: typ = OPENSSL_malloc(sizeof(*typ)); - if (!typ) + if (typ == NULL) return 0; typ->value.ptr = NULL; typ->type = -1; diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c index 8b62341b9b..10cc1f9143 100644 --- a/crypto/asn1/tasn_utl.c +++ b/crypto/asn1/tasn_utl.c @@ -172,7 +172,7 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, OPENSSL_free(enc->enc); enc->enc = OPENSSL_malloc(inlen); - if (!enc->enc) + if (enc->enc == NULL) return 0; memcpy(enc->enc, in, inlen); enc->len = inlen; diff --git a/crypto/asn1/x_bignum.c b/crypto/asn1/x_bignum.c index d2666e15da..e27480bdfb 100644 --- a/crypto/asn1/x_bignum.c +++ b/crypto/asn1/x_bignum.c @@ -111,7 +111,7 @@ ASN1_ITEM_end(CBIGNUM) static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) { *pval = (ASN1_VALUE *)BN_new(); - if (*pval) + if (*pval != NULL) return 1; else return 0; @@ -120,7 +120,7 @@ static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int bn_secure_new(ASN1_VALUE **pval, const ASN1_ITEM *it) { *pval = (ASN1_VALUE *)BN_secure_new(); - if (*pval) + if (*pval != NULL) return 1; else return 0; diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c index 961b913dc9..cb6f21f0c1 100644 --- a/crypto/asn1/x_pkey.c +++ b/crypto/asn1/x_pkey.c @@ -67,13 +67,13 @@ X509_PKEY *X509_PKEY_new(void) X509_PKEY *ret = NULL; ret = OPENSSL_zalloc(sizeof(*ret)); - if (!ret) + if (ret == NULL) goto err; ret->references = 1; ret->enc_algor = X509_ALGOR_new(); ret->enc_pkey = ASN1_OCTET_STRING_new(); - if (!ret->enc_algor || !ret->enc_pkey) + if (ret->enc_algor == NULL || ret->enc_pkey == NULL) goto err; return ret; diff --git a/crypto/asn1/x_pubkey.c b/crypto/asn1/x_pubkey.c index b2d81dfcc1..d20019005c 100644 --- a/crypto/asn1/x_pubkey.c +++ b/crypto/asn1/x_pubkey.c @@ -246,7 +246,7 @@ int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) { + if (pktmp == NULL) { ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } @@ -286,7 +286,7 @@ int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) if (!a) return 0; pktmp = EVP_PKEY_new(); - if (!pktmp) { + if (pktmp == NULL) { ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); return 0; } -- cgit v1.2.3