Don't cast malloc-family return values.
Also found some places where (a) blank line was missing; and (b)
the *wrong* return value was checked.
Reviewed-by: Richard Levitte <levitte@openssl.org>
BIO_ADDR *BIO_ADDR_new(void)
{
- BIO_ADDR *ret = (BIO_ADDR *)OPENSSL_zalloc(sizeof(BIO_ADDR));
+ BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret));
+
ret->sa.sa_family = AF_UNSPEC;
return ret;
}
{
OPENSSL_assert(bai != NULL);
- *bai = (BIO_ADDRINFO *)OPENSSL_zalloc(sizeof(**bai));
-
+ *bai = OPENSSL_zalloc(sizeof(**bai));
if (*bai == NULL)
return 0;
+
(*bai)->bai_family = family;
(*bai)->bai_socktype = socktype;
if (socktype == SOCK_STREAM)
EVP_CIPHER *EVP_CIPHER_meth_new(int cipher_type, int block_size, int key_len)
{
- EVP_CIPHER *cipher = (EVP_CIPHER *)OPENSSL_zalloc(sizeof(EVP_CIPHER));
+ EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
+
if (cipher != NULL) {
cipher->nid = cipher_type;
cipher->block_size = block_size;
{
EVP_CIPHER *to = EVP_CIPHER_meth_new(cipher->nid, cipher->block_size,
cipher->key_len);
- if (cipher != NULL)
+
+ if (to != NULL)
memcpy(to, cipher, sizeof(*to));
return to;
}
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void)
{
- return (EVP_ENCODE_CTX *)OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
+ return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
}
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx)
EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type)
{
- EVP_MD *md = (EVP_MD *)OPENSSL_zalloc(sizeof(EVP_MD));
+ EVP_MD *md = OPENSSL_zalloc(sizeof(*md));
+
if (md != NULL) {
md->type = md_type;
md->pkey_type = pkey_type;
EVP_MD *EVP_MD_meth_dup(const EVP_MD *md)
{
EVP_MD *to = EVP_MD_meth_new(md->type, md->pkey_type);
- if (md != NULL)
+
+ if (to != NULL)
memcpy(to, md, sizeof(*to));
return to;
}
HMAC_CTX *HMAC_CTX_new(void)
{
- HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));
- if (ctx)
+ HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(HMAC_CTX));
+
+ if (ctx != NULL) {
if (!HMAC_CTX_reset(ctx)) {
HMAC_CTX_free(ctx);
- ctx = NULL;
+ return NULL;
}
+ }
return ctx;
}