improve realloc/calloc/malloc patterns; ok guenther
authorderaadt <deraadt@openbsd.org>
Mon, 21 Apr 2014 11:37:41 +0000 (11:37 +0000)
committerderaadt <deraadt@openbsd.org>
Mon, 21 Apr 2014 11:37:41 +0000 (11:37 +0000)
32 files changed:
lib/libcrypto/asn1/a_bitstr.c
lib/libcrypto/asn1/a_bytes.c
lib/libcrypto/asn1/a_enum.c
lib/libcrypto/asn1/a_i2d_fp.c
lib/libcrypto/asn1/a_int.c
lib/libcrypto/asn1/a_object.c
lib/libcrypto/asn1/ameth_lib.c
lib/libcrypto/asn1/asn1_lib.c
lib/libcrypto/asn1/asn_mime.c
lib/libcrypto/asn1/f_enum.c
lib/libcrypto/asn1/f_int.c
lib/libcrypto/asn1/f_string.c
lib/libcrypto/asn1/n_pkey.c
lib/libcrypto/asn1/t_x509.c
lib/libcrypto/asn1/tasn_new.c
lib/libcrypto/asn1/x_info.c
lib/libssl/src/crypto/asn1/a_bitstr.c
lib/libssl/src/crypto/asn1/a_bytes.c
lib/libssl/src/crypto/asn1/a_enum.c
lib/libssl/src/crypto/asn1/a_i2d_fp.c
lib/libssl/src/crypto/asn1/a_int.c
lib/libssl/src/crypto/asn1/a_object.c
lib/libssl/src/crypto/asn1/ameth_lib.c
lib/libssl/src/crypto/asn1/asn1_lib.c
lib/libssl/src/crypto/asn1/asn_mime.c
lib/libssl/src/crypto/asn1/f_enum.c
lib/libssl/src/crypto/asn1/f_int.c
lib/libssl/src/crypto/asn1/f_string.c
lib/libssl/src/crypto/asn1/n_pkey.c
lib/libssl/src/crypto/asn1/t_x509.c
lib/libssl/src/crypto/asn1/tasn_new.c
lib/libssl/src/crypto/asn1/x_info.c

index c578ce6..f3cce8b 100644 (file)
@@ -153,7 +153,7 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
 
        if (len-- > 1) /* using one because of the bits left byte */
        {
-               s = (unsigned char *)malloc((int)len);
+               s = malloc((int)len);
                if (s == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -203,11 +203,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
        if ((a->length < (w + 1)) || (a->data == NULL)) {
                if (!value)
                        return(1); /* Don't need to set */
-               if (a->data == NULL)
-                       c = (unsigned char *)malloc(w + 1);
-               else
-                       c = (unsigned char *)OPENSSL_realloc_clean(a->data,
-                           a->length, w + 1);
+               c = OPENSSL_realloc_clean(a->data, a->length, w + 1);
                if (c == NULL) {
                        ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE);
                        return 0;
index 30647c9..34ed7b7 100644 (file)
@@ -99,7 +99,7 @@ d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
                ret = (*a);
 
        if (len != 0) {
-               s = (unsigned char *)malloc((int)len + 1);
+               s = malloc((int)len + 1);
                if (s == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -205,7 +205,7 @@ d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
                        if ((ret->length < len) || (ret->data == NULL)) {
                                if (ret->data != NULL)
                                        free(ret->data);
-                               s = (unsigned char *)malloc((int)len + 1);
+                               s = malloc(len + 1);
                                if (s == NULL) {
                                        i = ERR_R_MALLOC_FAILURE;
                                        goto err;
index 5e6f758..aa28c7c 100644 (file)
@@ -78,8 +78,7 @@ ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
        if (a->length < (int)(sizeof(long) + 1)) {
                if (a->data != NULL)
                        free(a->data);
-               if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
-                       memset((char *)a->data, 0, sizeof(long) + 1);
+               a->data = calloc(1, sizeof(long) + 1);
        }
        if (a->data == NULL) {
                ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
index 082ba1b..007e612 100644 (file)
@@ -89,7 +89,7 @@ ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
        int i, j = 0, n, ret = 1;
 
        n = i2d(x, NULL);
-       b = (char *)malloc(n);
+       b = malloc(n);
        if (b == NULL) {
                ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
                return (0);
index 05776f5..0559cce 100644 (file)
@@ -205,7 +205,7 @@ c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
 
        /* We must malloc stuff, even for 0 bytes otherwise it
         * signifies a missing NULL parameter. */
-       s = (unsigned char *)malloc((int)len + 1);
+       s = malloc((int)len + 1);
        if (s == NULL) {
                i = ERR_R_MALLOC_FAILURE;
                goto err;
@@ -309,7 +309,7 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
 
        /* We must malloc stuff, even for 0 bytes otherwise it
         * signifies a missing NULL parameter. */
-       s = (unsigned char *)malloc((int)len + 1);
+       s = malloc((int)len + 1);
        if (s == NULL) {
                i = ERR_R_MALLOC_FAILURE;
                goto err;
@@ -352,8 +352,7 @@ ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
        if (a->length < (int)(sizeof(long) + 1)) {
                if (a->data != NULL)
                        free(a->data);
-               if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
-                       memset((char *)a->data, 0, sizeof(long) + 1);
+               a->data = calloc(1, sizeof(long) + 1);
        }
        if (a->data == NULL) {
                ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
index 93c7552..f86d54f 100644 (file)
@@ -312,7 +312,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
                ret->length = 0;
                if (data != NULL)
                        free(data);
-               data = (unsigned char *)malloc(len ? (int)len : 1);
+               data = malloc(len ? (int)len : 1);
                if (data == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -345,7 +345,7 @@ ASN1_OBJECT_new(void)
 {
        ASN1_OBJECT *ret;
 
-       ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
+       ret = malloc(sizeof(ASN1_OBJECT));
        if (ret == NULL) {
                ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);
index 63ff18e..8652e93 100644 (file)
@@ -287,12 +287,10 @@ EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
 {
        EVP_PKEY_ASN1_METHOD *ameth;
 
-       ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD));
+       ameth = calloc(1, sizeof(EVP_PKEY_ASN1_METHOD));
        if (!ameth)
                return NULL;
 
-       memset(ameth, 0, sizeof(EVP_PKEY_ASN1_METHOD));
-
        ameth->pkey_id = id;
        ameth->pkey_base_id = id;
        ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
index f3b2f04..4d4368a 100644 (file)
@@ -418,7 +418,7 @@ ASN1_STRING_type_new(int type)
 {
        ASN1_STRING *ret;
 
-       ret = (ASN1_STRING *)malloc(sizeof(ASN1_STRING));
+       ret = malloc(sizeof(ASN1_STRING));
        if (ret == NULL) {
                ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);
index 8905575..248ea11 100644 (file)
@@ -850,7 +850,7 @@ mime_hdr_new(char *name, char *value)
                        }
                }
        } else tmpval = NULL;
-               mhdr = (MIME_HEADER *)malloc(sizeof(MIME_HEADER));
+               mhdr = malloc(sizeof(MIME_HEADER));
        if (!mhdr) {
                OPENSSL_free(tmpname);
                return NULL;
@@ -891,7 +891,7 @@ mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
        } else
                tmpval = NULL;
        /* Parameter values are case sensitive so leave as is */
-       mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM));
+       mparam = malloc(sizeof(MIME_PARAM));
        if (!mparam)
                return 0;
        mparam->param_name = tmpname;
index e8736e5..98fa312 100644 (file)
@@ -154,12 +154,7 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = (unsigned char *)realloc(s,
-                                   (unsigned int)num + i * 2);
+                       sp = realloc(s, (unsigned int)num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,
                                    ERR_R_MALLOC_FAILURE);
index f355dba..3f671d1 100644 (file)
@@ -158,12 +158,7 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = OPENSSL_realloc_clean(s, slen,
-                                   num + i * 2);
+                       sp = OPENSSL_realloc_clean(s, slen, num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_INTEGER,
                                    ERR_R_MALLOC_FAILURE);
index d42bcdb..c213c7a 100644 (file)
@@ -150,12 +150,7 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = (unsigned char *)realloc(s,
-                                   (unsigned int)num + i * 2);
+                       sp = realloc(s, (unsigned int)num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_STRING,
                                    ERR_R_MALLOC_FAILURE);
index 0e58baf..1a724cf 100644 (file)
@@ -163,7 +163,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
        }
 
        /* Since its RC4 encrypted length is actual length */
-       if ((zz = (unsigned char *)malloc(rsalen)) == NULL) {
+       if ((zz = malloc(rsalen)) == NULL) {
                ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE);
                goto err;
        }
index de3fa22..81333d6 100644 (file)
@@ -265,7 +265,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
        if (BIO_printf(bp, "        Subject OCSP hash: ") <= 0)
                goto err;
        derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
-       if ((der = dertmp = (unsigned char *)malloc (derlen)) == NULL)
+       if ((der = dertmp = malloc(derlen)) == NULL)
                goto err;
        i2d_X509_NAME(x->cert_info->subject, &dertmp);
 
index dc9ddc4..56c6a19 100644 (file)
@@ -156,10 +156,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                        }
                }
                if (!combine) {
-                       *pval = malloc(it->size);
+                       *pval = calloc(1, it->size);
                        if (!*pval)
                                goto memerr;
-                       memset(*pval, 0, it->size);
                }
                asn1_set_choice_selector(pval, -1, it);
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
@@ -181,10 +180,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                        }
                }
                if (!combine) {
-                       *pval = malloc(it->size);
+                       *pval = calloc(1, it->size);
                        if (!*pval)
                                goto memerr;
-                       memset(*pval, 0, it->size);
                        asn1_do_lock(pval, 0, it);
                        asn1_enc_init(pval, it);
                }
index 4d3e2eb..2d1bf0d 100644 (file)
@@ -67,7 +67,7 @@ X509_INFO_new(void)
 {
        X509_INFO *ret = NULL;
 
-       ret = (X509_INFO *)malloc(sizeof(X509_INFO));
+       ret = malloc(sizeof(X509_INFO));
        if (ret == NULL) {
                ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);
index c578ce6..f3cce8b 100644 (file)
@@ -153,7 +153,7 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
 
        if (len-- > 1) /* using one because of the bits left byte */
        {
-               s = (unsigned char *)malloc((int)len);
+               s = malloc((int)len);
                if (s == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -203,11 +203,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
        if ((a->length < (w + 1)) || (a->data == NULL)) {
                if (!value)
                        return(1); /* Don't need to set */
-               if (a->data == NULL)
-                       c = (unsigned char *)malloc(w + 1);
-               else
-                       c = (unsigned char *)OPENSSL_realloc_clean(a->data,
-                           a->length, w + 1);
+               c = OPENSSL_realloc_clean(a->data, a->length, w + 1);
                if (c == NULL) {
                        ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE);
                        return 0;
index 30647c9..34ed7b7 100644 (file)
@@ -99,7 +99,7 @@ d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
                ret = (*a);
 
        if (len != 0) {
-               s = (unsigned char *)malloc((int)len + 1);
+               s = malloc((int)len + 1);
                if (s == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -205,7 +205,7 @@ d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
                        if ((ret->length < len) || (ret->data == NULL)) {
                                if (ret->data != NULL)
                                        free(ret->data);
-                               s = (unsigned char *)malloc((int)len + 1);
+                               s = malloc(len + 1);
                                if (s == NULL) {
                                        i = ERR_R_MALLOC_FAILURE;
                                        goto err;
index 5e6f758..aa28c7c 100644 (file)
@@ -78,8 +78,7 @@ ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
        if (a->length < (int)(sizeof(long) + 1)) {
                if (a->data != NULL)
                        free(a->data);
-               if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
-                       memset((char *)a->data, 0, sizeof(long) + 1);
+               a->data = calloc(1, sizeof(long) + 1);
        }
        if (a->data == NULL) {
                ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE);
index 082ba1b..007e612 100644 (file)
@@ -89,7 +89,7 @@ ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
        int i, j = 0, n, ret = 1;
 
        n = i2d(x, NULL);
-       b = (char *)malloc(n);
+       b = malloc(n);
        if (b == NULL) {
                ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);
                return (0);
index 05776f5..0559cce 100644 (file)
@@ -205,7 +205,7 @@ c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
 
        /* We must malloc stuff, even for 0 bytes otherwise it
         * signifies a missing NULL parameter. */
-       s = (unsigned char *)malloc((int)len + 1);
+       s = malloc((int)len + 1);
        if (s == NULL) {
                i = ERR_R_MALLOC_FAILURE;
                goto err;
@@ -309,7 +309,7 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
 
        /* We must malloc stuff, even for 0 bytes otherwise it
         * signifies a missing NULL parameter. */
-       s = (unsigned char *)malloc((int)len + 1);
+       s = malloc((int)len + 1);
        if (s == NULL) {
                i = ERR_R_MALLOC_FAILURE;
                goto err;
@@ -352,8 +352,7 @@ ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
        if (a->length < (int)(sizeof(long) + 1)) {
                if (a->data != NULL)
                        free(a->data);
-               if ((a->data = (unsigned char *)malloc(sizeof(long) + 1)) != NULL)
-                       memset((char *)a->data, 0, sizeof(long) + 1);
+               a->data = calloc(1, sizeof(long) + 1);
        }
        if (a->data == NULL) {
                ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE);
index 93c7552..f86d54f 100644 (file)
@@ -312,7 +312,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
                ret->length = 0;
                if (data != NULL)
                        free(data);
-               data = (unsigned char *)malloc(len ? (int)len : 1);
+               data = malloc(len ? (int)len : 1);
                if (data == NULL) {
                        i = ERR_R_MALLOC_FAILURE;
                        goto err;
@@ -345,7 +345,7 @@ ASN1_OBJECT_new(void)
 {
        ASN1_OBJECT *ret;
 
-       ret = (ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
+       ret = malloc(sizeof(ASN1_OBJECT));
        if (ret == NULL) {
                ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);
index 63ff18e..8652e93 100644 (file)
@@ -287,12 +287,10 @@ EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info)
 {
        EVP_PKEY_ASN1_METHOD *ameth;
 
-       ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD));
+       ameth = calloc(1, sizeof(EVP_PKEY_ASN1_METHOD));
        if (!ameth)
                return NULL;
 
-       memset(ameth, 0, sizeof(EVP_PKEY_ASN1_METHOD));
-
        ameth->pkey_id = id;
        ameth->pkey_base_id = id;
        ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;
index f3b2f04..4d4368a 100644 (file)
@@ -418,7 +418,7 @@ ASN1_STRING_type_new(int type)
 {
        ASN1_STRING *ret;
 
-       ret = (ASN1_STRING *)malloc(sizeof(ASN1_STRING));
+       ret = malloc(sizeof(ASN1_STRING));
        if (ret == NULL) {
                ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);
index 8905575..248ea11 100644 (file)
@@ -850,7 +850,7 @@ mime_hdr_new(char *name, char *value)
                        }
                }
        } else tmpval = NULL;
-               mhdr = (MIME_HEADER *)malloc(sizeof(MIME_HEADER));
+               mhdr = malloc(sizeof(MIME_HEADER));
        if (!mhdr) {
                OPENSSL_free(tmpname);
                return NULL;
@@ -891,7 +891,7 @@ mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
        } else
                tmpval = NULL;
        /* Parameter values are case sensitive so leave as is */
-       mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM));
+       mparam = malloc(sizeof(MIME_PARAM));
        if (!mparam)
                return 0;
        mparam->param_name = tmpname;
index e8736e5..98fa312 100644 (file)
@@ -154,12 +154,7 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = (unsigned char *)realloc(s,
-                                   (unsigned int)num + i * 2);
+                       sp = realloc(s, (unsigned int)num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,
                                    ERR_R_MALLOC_FAILURE);
index f355dba..3f671d1 100644 (file)
@@ -158,12 +158,7 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = OPENSSL_realloc_clean(s, slen,
-                                   num + i * 2);
+                       sp = OPENSSL_realloc_clean(s, slen, num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_INTEGER,
                                    ERR_R_MALLOC_FAILURE);
index d42bcdb..c213c7a 100644 (file)
@@ -150,12 +150,7 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
                }
                i /= 2;
                if (num + i > slen) {
-                       if (s == NULL)
-                               sp = (unsigned char *)malloc(
-                                   (unsigned int)num + i * 2);
-                       else
-                               sp = (unsigned char *)realloc(s,
-                                   (unsigned int)num + i * 2);
+                       sp = realloc(s, (unsigned int)num + i * 2);
                        if (sp == NULL) {
                                ASN1err(ASN1_F_A2I_ASN1_STRING,
                                    ERR_R_MALLOC_FAILURE);
index 0e58baf..1a724cf 100644 (file)
@@ -163,7 +163,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
        }
 
        /* Since its RC4 encrypted length is actual length */
-       if ((zz = (unsigned char *)malloc(rsalen)) == NULL) {
+       if ((zz = malloc(rsalen)) == NULL) {
                ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE);
                goto err;
        }
index de3fa22..81333d6 100644 (file)
@@ -265,7 +265,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
        if (BIO_printf(bp, "        Subject OCSP hash: ") <= 0)
                goto err;
        derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
-       if ((der = dertmp = (unsigned char *)malloc (derlen)) == NULL)
+       if ((der = dertmp = malloc(derlen)) == NULL)
                goto err;
        i2d_X509_NAME(x->cert_info->subject, &dertmp);
 
index dc9ddc4..56c6a19 100644 (file)
@@ -156,10 +156,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                        }
                }
                if (!combine) {
-                       *pval = malloc(it->size);
+                       *pval = calloc(1, it->size);
                        if (!*pval)
                                goto memerr;
-                       memset(*pval, 0, it->size);
                }
                asn1_set_choice_selector(pval, -1, it);
                if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
@@ -181,10 +180,9 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
                        }
                }
                if (!combine) {
-                       *pval = malloc(it->size);
+                       *pval = calloc(1, it->size);
                        if (!*pval)
                                goto memerr;
-                       memset(*pval, 0, it->size);
                        asn1_do_lock(pval, 0, it);
                        asn1_enc_init(pval, it);
                }
index 4d3e2eb..2d1bf0d 100644 (file)
@@ -67,7 +67,7 @@ X509_INFO_new(void)
 {
        X509_INFO *ret = NULL;
 
-       ret = (X509_INFO *)malloc(sizeof(X509_INFO));
+       ret = malloc(sizeof(X509_INFO));
        if (ret == NULL) {
                ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
                return (NULL);