Apply the semantic patch rm-malloc-cast.cocci.
for dir in library programs; do
spatch --sp-file scripts/rm-malloc-cast.cocci --dir $dir \
--in-place;
done
diff --git a/library/asn1parse.c b/library/asn1parse.c
index 763f32a..4847f78 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -270,7 +270,7 @@
/* Allocate and assign next pointer */
if( *p < end )
{
- cur->next = (asn1_sequence *) polarssl_malloc(
+ cur->next = polarssl_malloc(
sizeof( asn1_sequence ) );
if( cur->next == NULL )
diff --git a/library/bignum.c b/library/bignum.c
index e2cb92e..91c7963 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -109,7 +109,7 @@
if( X->n < nblimbs )
{
- if( ( p = (t_uint *) polarssl_malloc( nblimbs * ciL ) ) == NULL )
+ if( ( p = polarssl_malloc( nblimbs * ciL ) ) == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
memset( p, 0, nblimbs * ciL );
@@ -149,7 +149,7 @@
if( i < nblimbs )
i = nblimbs;
- if( ( p = (t_uint *) polarssl_malloc( i * ciL ) ) == NULL )
+ if( ( p = polarssl_malloc( i * ciL ) ) == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
memset( p, 0, i * ciL );
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 736c292..c958cf6 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -182,7 +182,7 @@
static void * aes_ctx_alloc( void )
{
- aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
+ aes_context *aes = polarssl_malloc( sizeof( aes_context ) );
if( aes == NULL )
return( NULL );
@@ -544,7 +544,7 @@
static void * camellia_ctx_alloc( void )
{
camellia_context *ctx;
- ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
+ ctx = polarssl_malloc( sizeof( camellia_context ) );
if( ctx == NULL )
return( NULL );
@@ -925,7 +925,7 @@
static void * des_ctx_alloc( void )
{
- des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
+ des_context *des = polarssl_malloc( sizeof( des_context ) );
if( des == NULL )
return( NULL );
@@ -944,7 +944,7 @@
static void * des3_ctx_alloc( void )
{
des3_context *des3;
- des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
+ des3 = polarssl_malloc( sizeof( des3_context ) );
if( des3 == NULL )
return( NULL );
@@ -1148,7 +1148,7 @@
static void * blowfish_ctx_alloc( void )
{
blowfish_context *ctx;
- ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
+ ctx = polarssl_malloc( sizeof( blowfish_context ) );
if( ctx == NULL )
return( NULL );
@@ -1250,7 +1250,7 @@
static void * arc4_ctx_alloc( void )
{
arc4_context *ctx;
- ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
+ ctx = polarssl_malloc( sizeof( arc4_context ) );
if( ctx == NULL )
return( NULL );
diff --git a/library/dhm.c b/library/dhm.c
index 5861f94..a7b275f 100644
--- a/library/dhm.c
+++ b/library/dhm.c
@@ -507,7 +507,7 @@
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
+ ( *buf = polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( POLARSSL_ERR_DHM_MALLOC_FAILED );
diff --git a/library/ecp.c b/library/ecp.c
index 1bb8dfe..298c964 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -813,7 +813,7 @@
if( t_len < 2 )
return( ecp_normalize_jac( grp, *T ) );
- if( ( c = (mpi *) polarssl_malloc( t_len * sizeof( mpi ) ) ) == NULL )
+ if( ( c = polarssl_malloc( t_len * sizeof( mpi ) ) ) == NULL )
return( POLARSSL_ERR_ECP_MALLOC_FAILED );
mpi_init( &u ); mpi_init( &Zi ); mpi_init( &ZZi );
@@ -1416,7 +1416,7 @@
if( T == NULL )
{
- T = (ecp_point *) polarssl_malloc( pre_len * sizeof( ecp_point ) );
+ T = polarssl_malloc( pre_len * sizeof( ecp_point ) );
if( T == NULL )
{
ret = POLARSSL_ERR_ECP_MALLOC_FAILED;
diff --git a/library/md_wrap.c b/library/md_wrap.c
index 9554373..ed5a63e 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -395,7 +395,7 @@
static void * ripemd160_ctx_alloc( void )
{
ripemd160_context *ctx;
- ctx = (ripemd160_context *) polarssl_malloc( sizeof( ripemd160_context ) );
+ ctx = polarssl_malloc( sizeof( ripemd160_context ) );
if( ctx == NULL )
return( NULL );
@@ -491,7 +491,7 @@
static void * sha1_ctx_alloc( void )
{
sha1_context *ctx;
- ctx = (sha1_context *) polarssl_malloc( sizeof( sha1_context ) );
+ ctx = polarssl_malloc( sizeof( sha1_context ) );
if( ctx == NULL )
return( NULL );
@@ -700,7 +700,7 @@
static void * sha256_ctx_alloc( void )
{
sha256_context *ctx;
- ctx = (sha256_context *) polarssl_malloc( sizeof( sha256_context ) );
+ ctx = polarssl_malloc( sizeof( sha256_context ) );
if( ctx == NULL )
return( NULL );
@@ -906,7 +906,7 @@
static void * sha512_ctx_alloc( void )
{
sha512_context *ctx;
- ctx = (sha512_context *) polarssl_malloc( sizeof( sha512_context ) );
+ ctx = polarssl_malloc( sizeof( sha512_context ) );
if( ctx == NULL )
return( NULL );
diff --git a/library/pem.c b/library/pem.c
index b5e8eee..d850d40 100644
--- a/library/pem.c
+++ b/library/pem.c
@@ -321,7 +321,7 @@
if( ret == POLARSSL_ERR_BASE64_INVALID_CHARACTER )
return( POLARSSL_ERR_PEM_INVALID_DATA + ret );
- if( ( buf = (unsigned char *) polarssl_malloc( len ) ) == NULL )
+ if( ( buf = polarssl_malloc( len ) ) == NULL )
return( POLARSSL_ERR_PEM_MALLOC_FAILED );
if( ( ret = base64_decode( buf, &len, s1, s2 - s1 ) ) != 0 )
diff --git a/library/pkparse.c b/library/pkparse.c
index 4ca359a..d8ee64a 100644
--- a/library/pkparse.c
+++ b/library/pkparse.c
@@ -89,7 +89,7 @@
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
+ ( *buf = polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( POLARSSL_ERR_PK_MALLOC_FAILED );
diff --git a/library/ssl_cache.c b/library/ssl_cache.c
index 30da95a..7519f36 100644
--- a/library/ssl_cache.c
+++ b/library/ssl_cache.c
@@ -103,7 +103,7 @@
*/
if( entry->peer_cert.p != NULL )
{
- if( ( session->peer_cert = (x509_crt *) polarssl_malloc(
+ if( ( session->peer_cert = polarssl_malloc(
sizeof(x509_crt) ) ) == NULL )
{
ret = 1;
@@ -222,7 +222,7 @@
/*
* max_entries not reached, create new entry
*/
- cur = (ssl_cache_entry *) polarssl_malloc( sizeof(ssl_cache_entry) );
+ cur = polarssl_malloc( sizeof(ssl_cache_entry) );
if( cur == NULL )
{
ret = 1;
@@ -259,7 +259,7 @@
*/
if( session->peer_cert != NULL )
{
- cur->peer_cert.p = (unsigned char *) polarssl_malloc(
+ cur->peer_cert.p = polarssl_malloc(
session->peer_cert->raw.len );
if( cur->peer_cert.p == NULL )
{
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 2df8134..f526b5f 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -93,7 +93,7 @@
{
int ret;
- dst->peer_cert = (x509_crt *) polarssl_malloc( sizeof(x509_crt) );
+ dst->peer_cert = polarssl_malloc( sizeof(x509_crt) );
if( dst->peer_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
@@ -112,7 +112,7 @@
#if defined(POLARSSL_SSL_SESSION_TICKETS)
if( src->ticket != NULL )
{
- dst->ticket = (unsigned char *) polarssl_malloc( src->ticket_len );
+ dst->ticket = polarssl_malloc( src->ticket_len );
if( dst->ticket == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
@@ -2748,7 +2748,7 @@
polarssl_free( ssl->session_negotiate->peer_cert );
}
- if( ( ssl->session_negotiate->peer_cert = (x509_crt *) polarssl_malloc(
+ if( ( ssl->session_negotiate->peer_cert = polarssl_malloc(
sizeof( x509_crt ) ) ) == NULL )
{
SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed",
@@ -3545,19 +3545,19 @@
*/
if( ssl->transform_negotiate == NULL )
{
- ssl->transform_negotiate = (ssl_transform *) polarssl_malloc(
+ ssl->transform_negotiate = polarssl_malloc(
sizeof(ssl_transform) );
}
if( ssl->session_negotiate == NULL )
{
- ssl->session_negotiate = (ssl_session *) polarssl_malloc(
+ ssl->session_negotiate = polarssl_malloc(
sizeof(ssl_session) );
}
if( ssl->handshake == NULL )
{
- ssl->handshake = (ssl_handshake_params *)
+ ssl->handshake =
polarssl_malloc( sizeof(ssl_handshake_params) );
}
@@ -3631,7 +3631,7 @@
/*
* Prepare base structures
*/
- ssl->in_ctr = (unsigned char *) polarssl_malloc( len );
+ ssl->in_ctr = polarssl_malloc( len );
ssl->in_hdr = ssl->in_ctr + 8;
ssl->in_iv = ssl->in_ctr + 13;
ssl->in_msg = ssl->in_ctr + 13;
@@ -3642,7 +3642,7 @@
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
}
- ssl->out_ctr = (unsigned char *) polarssl_malloc( len );
+ ssl->out_ctr = polarssl_malloc( len );
ssl->out_hdr = ssl->out_ctr + 8;
ssl->out_iv = ssl->out_ctr + 13;
ssl->out_msg = ssl->out_ctr + 13;
@@ -3783,7 +3783,7 @@
if( ssl->ticket_keys != NULL )
return( 0 );
- tkeys = (ssl_ticket_keys *) polarssl_malloc( sizeof(ssl_ticket_keys) );
+ tkeys = polarssl_malloc( sizeof(ssl_ticket_keys) );
if( tkeys == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
@@ -3940,7 +3940,7 @@
{
ssl_key_cert *key_cert, *last;
- key_cert = (ssl_key_cert *) polarssl_malloc( sizeof(ssl_key_cert) );
+ key_cert = polarssl_malloc( sizeof(ssl_key_cert) );
if( key_cert == NULL )
return( NULL );
@@ -3996,7 +3996,7 @@
if( key_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
- key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
+ key_cert->key = polarssl_malloc( sizeof(pk_context) );
if( key_cert->key == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
@@ -4028,7 +4028,7 @@
if( key_cert == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
- key_cert->key = (pk_context *) polarssl_malloc( sizeof(pk_context) );
+ key_cert->key = polarssl_malloc( sizeof(pk_context) );
if( key_cert->key == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
@@ -4064,8 +4064,8 @@
ssl->psk_len = psk_len;
ssl->psk_identity_len = psk_identity_len;
- ssl->psk = (unsigned char *) polarssl_malloc( ssl->psk_len );
- ssl->psk_identity = (unsigned char *)
+ ssl->psk = polarssl_malloc( ssl->psk_len );
+ ssl->psk_identity =
polarssl_malloc( ssl->psk_identity_len );
if( ssl->psk == NULL || ssl->psk_identity == NULL )
@@ -4148,7 +4148,7 @@
if( ssl->hostname_len + 1 == 0 )
return( POLARSSL_ERR_SSL_BAD_INPUT_DATA );
- ssl->hostname = (unsigned char *) polarssl_malloc( ssl->hostname_len + 1 );
+ ssl->hostname = polarssl_malloc( ssl->hostname_len + 1 );
if( ssl->hostname == NULL )
return( POLARSSL_ERR_SSL_MALLOC_FAILED );
diff --git a/library/x509.c b/library/x509.c
index 955d349..3818c3f 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -451,7 +451,7 @@
/* Mark this item as being only one in a set */
cur->next_merged = 1;
- cur->next = (x509_name *) polarssl_malloc( sizeof( x509_name ) );
+ cur->next = polarssl_malloc( sizeof( x509_name ) );
if( cur->next == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
@@ -467,7 +467,7 @@
if( *p == end )
return( 0 );
- cur->next = (x509_name *) polarssl_malloc( sizeof( x509_name ) );
+ cur->next = polarssl_malloc( sizeof( x509_name ) );
if( cur->next == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
diff --git a/library/x509_crl.c b/library/x509_crl.c
index ce6df6e..78b925c 100644
--- a/library/x509_crl.c
+++ b/library/x509_crl.c
@@ -279,7 +279,7 @@
if( crl->version != 0 && crl->next == NULL )
{
- crl->next = (x509_crl *) polarssl_malloc( sizeof( x509_crl ) );
+ crl->next = polarssl_malloc( sizeof( x509_crl ) );
if( crl->next == NULL )
{
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 565435c..9d5aa94 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -359,7 +359,7 @@
if( cur->next != NULL )
return( POLARSSL_ERR_X509_INVALID_EXTENSIONS );
- cur->next = (asn1_sequence *) polarssl_malloc(
+ cur->next = polarssl_malloc(
sizeof( asn1_sequence ) );
if( cur->next == NULL )
@@ -553,7 +553,7 @@
if( crt == NULL || buf == NULL )
return( POLARSSL_ERR_X509_BAD_INPUT_DATA );
- p = (unsigned char *) polarssl_malloc( len = buflen );
+ p = polarssl_malloc( len = buflen );
if( p == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
@@ -810,7 +810,7 @@
*/
if( crt->version != 0 && crt->next == NULL )
{
- crt->next = (x509_crt *) polarssl_malloc( sizeof( x509_crt ) );
+ crt->next = polarssl_malloc( sizeof( x509_crt ) );
if( crt->next == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );
diff --git a/library/x509_csr.c b/library/x509_csr.c
index a5c9693..ad49abc 100644
--- a/library/x509_csr.c
+++ b/library/x509_csr.c
@@ -112,7 +112,7 @@
/*
* first copy the raw DER data
*/
- p = (unsigned char *) polarssl_malloc( len = buflen );
+ p = polarssl_malloc( len = buflen );
if( p == NULL )
return( POLARSSL_ERR_X509_MALLOC_FAILED );