Don't cast |OPENSSL_malloc|/|OPENSSL_realloc| result.
C has implicit conversion of |void *| to other pointer types so these
casts are unnecessary. Clean them up to make the code easier to read
and to make it easier to find dangerous casts.
Change-Id: I26988a672e8ed4d69c75cfbb284413999b475464
Reviewed-on: https://boringssl-review.googlesource.com/7102
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/crypto/bio/buffer.c b/crypto/bio/buffer.c
index 9d0cb3c..1557451 100644
--- a/crypto/bio/buffer.c
+++ b/crypto/bio/buffer.c
@@ -100,7 +100,7 @@
if (ctx->ibuf == NULL) {
goto err1;
}
- ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ ctx->obuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
if (ctx->obuf == NULL) {
goto err2;
}
@@ -340,13 +340,13 @@
p1 = ctx->ibuf;
p2 = ctx->obuf;
if (ibs > DEFAULT_BUFFER_SIZE && ibs != ctx->ibuf_size) {
- p1 = (char *)OPENSSL_malloc(ibs);
+ p1 = OPENSSL_malloc(ibs);
if (p1 == NULL) {
goto malloc_error;
}
}
if (obs > DEFAULT_BUFFER_SIZE && obs != ctx->obuf_size) {
- p2 = (char *)OPENSSL_malloc(obs);
+ p2 = OPENSSL_malloc(obs);
if (p2 == NULL) {
if (p1 != ctx->ibuf) {
OPENSSL_free(p1);
diff --git a/crypto/bn/bn.c b/crypto/bn/bn.c
index 543c148..2263701 100644
--- a/crypto/bn/bn.c
+++ b/crypto/bn/bn.c
@@ -295,7 +295,7 @@
return NULL;
}
- a = (BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG) * words);
+ a = OPENSSL_malloc(sizeof(BN_ULONG) * words);
if (a == NULL) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/bn/convert.c b/crypto/bn/convert.c
index 1f7af64..542f523 100644
--- a/crypto/bn/convert.c
+++ b/crypto/bn/convert.c
@@ -208,7 +208,7 @@
char *buf;
char *p;
- buf = (char *)OPENSSL_malloc(bn->top * BN_BYTES * 2 + 2);
+ buf = OPENSSL_malloc(bn->top * BN_BYTES * 2 + 2);
if (buf == NULL) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
return NULL;
@@ -385,9 +385,8 @@
*/
i = BN_num_bits(a) * 3;
num = i / 10 + i / 1000 + 1 + 1;
- bn_data =
- (BN_ULONG *)OPENSSL_malloc((num / BN_DEC_NUM + 1) * sizeof(BN_ULONG));
- buf = (char *)OPENSSL_malloc(num + 3);
+ bn_data = OPENSSL_malloc((num / BN_DEC_NUM + 1) * sizeof(BN_ULONG));
+ buf = OPENSSL_malloc(num + 3);
if ((buf == NULL) || (bn_data == NULL)) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
goto err;
diff --git a/crypto/bn/exponentiation.c b/crypto/bn/exponentiation.c
index 72a8db4..f7100ac 100644
--- a/crypto/bn/exponentiation.c
+++ b/crypto/bn/exponentiation.c
@@ -954,7 +954,7 @@
} else
#endif
{
- if ((powerbufFree = (unsigned char *)OPENSSL_malloc(
+ if ((powerbufFree = OPENSSL_malloc(
powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) {
goto err;
}
diff --git a/crypto/dh/dh.c b/crypto/dh/dh.c
index bf6196c..aed8720 100644
--- a/crypto/dh/dh.c
+++ b/crypto/dh/dh.c
@@ -74,7 +74,7 @@
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
DH *DH_new(void) {
- DH *dh = (DH *)OPENSSL_malloc(sizeof(DH));
+ DH *dh = OPENSSL_malloc(sizeof(DH));
if (dh == NULL) {
OPENSSL_PUT_ERROR(DH, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c
index ebe55e8..1e44692 100644
--- a/crypto/dsa/dsa.c
+++ b/crypto/dsa/dsa.c
@@ -86,7 +86,7 @@
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
DSA *DSA_new(void) {
- DSA *dsa = (DSA *)OPENSSL_malloc(sizeof(DSA));
+ DSA *dsa = OPENSSL_malloc(sizeof(DSA));
if (dsa == NULL) {
OPENSSL_PUT_ERROR(DSA, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index d3bf4c6..5b015f5 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -85,7 +85,7 @@
EC_KEY *EC_KEY_new(void) { return EC_KEY_new_method(NULL); }
EC_KEY *EC_KEY_new_method(const ENGINE *engine) {
- EC_KEY *ret = (EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));
+ EC_KEY *ret = OPENSSL_malloc(sizeof(EC_KEY));
if (ret == NULL) {
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/evp/p_dsa_asn1.c b/crypto/evp/p_dsa_asn1.c
index ea75e58..a876eef 100644
--- a/crypto/evp/p_dsa_asn1.c
+++ b/crypto/evp/p_dsa_asn1.c
@@ -436,7 +436,7 @@
update_buflen(priv_key, &buf_len);
update_buflen(pub_key, &buf_len);
- m = (uint8_t *)OPENSSL_malloc(buf_len + 10);
+ m = OPENSSL_malloc(buf_len + 10);
if (m == NULL) {
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
goto err;
diff --git a/crypto/evp/p_ec_asn1.c b/crypto/evp/p_ec_asn1.c
index e12508d..e093c18 100644
--- a/crypto/evp/p_ec_asn1.c
+++ b/crypto/evp/p_ec_asn1.c
@@ -279,7 +279,7 @@
OPENSSL_PUT_ERROR(EVP, ERR_R_EC_LIB);
return 0;
}
- ep = (uint8_t *)OPENSSL_malloc(eplen);
+ ep = OPENSSL_malloc(eplen);
if (!ep) {
EC_KEY_set_enc_flags(ec_key, old_flags);
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
diff --git a/crypto/evp/p_rsa_asn1.c b/crypto/evp/p_rsa_asn1.c
index 8556b5a..70f0b76 100644
--- a/crypto/evp/p_rsa_asn1.c
+++ b/crypto/evp/p_rsa_asn1.c
@@ -216,7 +216,7 @@
}
}
- m = (uint8_t *)OPENSSL_malloc(buf_len + 10);
+ m = OPENSSL_malloc(buf_len + 10);
if (m == NULL) {
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
goto err;
diff --git a/crypto/modes/gcm.c b/crypto/modes/gcm.c
index 65451a6..2519b19 100644
--- a/crypto/modes/gcm.c
+++ b/crypto/modes/gcm.c
@@ -408,7 +408,7 @@
GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key, block128_f block) {
GCM128_CONTEXT *ret;
- ret = (GCM128_CONTEXT *)OPENSSL_malloc(sizeof(GCM128_CONTEXT));
+ ret = OPENSSL_malloc(sizeof(GCM128_CONTEXT));
if (ret != NULL) {
CRYPTO_gcm128_init(ret, key, block);
}
diff --git a/crypto/rsa/rsa.c b/crypto/rsa/rsa.c
index 6c28ad7..9ffea1f 100644
--- a/crypto/rsa/rsa.c
+++ b/crypto/rsa/rsa.c
@@ -76,7 +76,7 @@
RSA *RSA_new(void) { return RSA_new_method(NULL); }
RSA *RSA_new_method(const ENGINE *engine) {
- RSA *rsa = (RSA *)OPENSSL_malloc(sizeof(RSA));
+ RSA *rsa = OPENSSL_malloc(sizeof(RSA));
if (rsa == NULL) {
OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/ssl/pqueue/pqueue.c b/ssl/pqueue/pqueue.c
index 14bd9b6..e689761 100644
--- a/ssl/pqueue/pqueue.c
+++ b/ssl/pqueue/pqueue.c
@@ -69,7 +69,7 @@
pitem *pitem_new(uint8_t prio64be[8], void *data) {
- pitem *item = (pitem *)OPENSSL_malloc(sizeof(pitem));
+ pitem *item = OPENSSL_malloc(sizeof(pitem));
if (item == NULL) {
return NULL;
}
@@ -91,7 +91,7 @@
}
pqueue pqueue_new(void) {
- pqueue_s *pq = (pqueue_s *)OPENSSL_malloc(sizeof(pqueue_s));
+ pqueue_s *pq = OPENSSL_malloc(sizeof(pqueue_s));
if (pq == NULL) {
return NULL;
}
diff --git a/ssl/ssl_aead_ctx.c b/ssl/ssl_aead_ctx.c
index 8829679..ea44a6c 100644
--- a/ssl/ssl_aead_ctx.c
+++ b/ssl/ssl_aead_ctx.c
@@ -56,7 +56,7 @@
enc_key_len += fixed_iv_len;
}
- SSL_AEAD_CTX *aead_ctx = (SSL_AEAD_CTX *)OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
+ SSL_AEAD_CTX *aead_ctx = OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
if (aead_ctx == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c
index 4952cfd..983e1a7 100644
--- a/ssl/ssl_cert.c
+++ b/ssl/ssl_cert.c
@@ -139,7 +139,7 @@
}
CERT *ssl_cert_new(void) {
- CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
+ CERT *ret = OPENSSL_malloc(sizeof(CERT));
if (ret == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
@@ -150,7 +150,7 @@
}
CERT *ssl_cert_dup(CERT *cert) {
- CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
+ CERT *ret = OPENSSL_malloc(sizeof(CERT));
if (ret == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/ssl/ssl_cipher.c b/ssl/ssl_cipher.c
index ba73848..4ff9f5c 100644
--- a/ssl/ssl_cipher.c
+++ b/ssl/ssl_cipher.c
@@ -1392,7 +1392,7 @@
/* Now we have to collect the available ciphers from the compiled in ciphers.
* We cannot get more than the number compiled in, so it is used for
* allocation. */
- co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * kCiphersLen);
+ co_list = OPENSSL_malloc(sizeof(CIPHER_ORDER) * kCiphersLen);
if (co_list == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 56edf2f..542dc17 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -221,7 +221,7 @@
goto err;
}
- ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
+ ret = OPENSSL_malloc(sizeof(SSL_CTX));
if (ret == NULL) {
goto err;
}
@@ -353,7 +353,7 @@
return NULL;
}
- SSL *ssl = (SSL *)OPENSSL_malloc(sizeof(SSL));
+ SSL *ssl = OPENSSL_malloc(sizeof(SSL));
if (ssl == NULL) {
goto err;
}
diff --git a/ssl/ssl_session.c b/ssl/ssl_session.c
index 24de4ec..804a04f 100644
--- a/ssl/ssl_session.c
+++ b/ssl/ssl_session.c
@@ -161,7 +161,7 @@
static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *session, int lock);
SSL_SESSION *SSL_SESSION_new(void) {
- SSL_SESSION *session = (SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));
+ SSL_SESSION *session = OPENSSL_malloc(sizeof(SSL_SESSION));
if (session == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return 0;
diff --git a/ssl/t1_enc.c b/ssl/t1_enc.c
index a64e9d8..216514d 100644
--- a/ssl/t1_enc.c
+++ b/ssl/t1_enc.c
@@ -373,7 +373,7 @@
ssl3_cleanup_key_block(ssl);
- uint8_t *keyblock = (uint8_t *)OPENSSL_malloc(key_block_len);
+ uint8_t *keyblock = OPENSSL_malloc(key_block_len);
if (keyblock == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return 0;
diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c
index c010d7f..434286b 100644
--- a/ssl/t1_lib.c
+++ b/ssl/t1_lib.c
@@ -169,8 +169,7 @@
return 1;
}
- extension_types =
- (uint16_t *)OPENSSL_malloc(sizeof(uint16_t) * num_extensions);
+ extension_types = OPENSSL_malloc(sizeof(uint16_t) * num_extensions);
if (extension_types == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
goto done;
@@ -377,7 +376,7 @@
uint16_t *curve_ids;
size_t i;
- curve_ids = (uint16_t *)OPENSSL_malloc(ncurves * sizeof(uint16_t));
+ curve_ids = OPENSSL_malloc(ncurves * sizeof(uint16_t));
if (curve_ids == NULL) {
return 0;
}
@@ -1905,9 +1904,7 @@
return 0;
}
- ssl->s3->tmp.peer_ellipticcurvelist =
- (uint16_t *)OPENSSL_malloc(CBS_len(&elliptic_curve_list));
-
+ ssl->s3->tmp.peer_ellipticcurvelist = OPENSSL_malloc(CBS_len(&elliptic_curve_list));
if (ssl->s3->tmp.peer_ellipticcurvelist == NULL) {
*out_alert = SSL_AD_INTERNAL_ERROR;
return 0;