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
This commit is contained in:
Mansour Moufid 2015-02-15 17:35:38 -05:00 committed by Manuel Pégourié-Gonnard
parent fd9afb29d3
commit c531b4af3c
16 changed files with 46 additions and 46 deletions

View file

@ -270,7 +270,7 @@ int asn1_get_sequence_of( unsigned char **p,
/* 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 )

View file

@ -109,7 +109,7 @@ int mpi_grow( mpi *X, size_t nblimbs )
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 @@ int mpi_shrink( mpi *X, size_t nblimbs )
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 );

View file

@ -182,7 +182,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
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 int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
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 int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
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 des_ctx_free( void *ctx )
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 int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
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 int arc4_setkey_wrap( void *ctx, const unsigned char *key,
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 );

View file

@ -507,7 +507,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
*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 );

View file

@ -813,7 +813,7 @@ static int ecp_normalize_jac_many( const ecp_group *grp,
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 @@ static int ecp_mul_comb( ecp_group *grp, ecp_point *R,
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;

View file

@ -395,7 +395,7 @@ static void ripemd160_hmac_reset_wrap( void *ctx )
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_hmac_reset_wrap( void *ctx )
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_hmac_wrap( const unsigned char *key, size_t keylen,
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_hmac_wrap( const unsigned char *key, size_t keylen,
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 );

View file

@ -321,7 +321,7 @@ int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
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 )

View file

@ -89,7 +89,7 @@ int pk_load_file( const char *path, unsigned char **buf, size_t *n )
*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 );

View file

@ -103,7 +103,7 @@ int ssl_cache_get( void *data, ssl_session *session )
*/
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 @@ int ssl_cache_set( void *data, const ssl_session *session )
/*
* 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 @@ int ssl_cache_set( void *data, const ssl_session *session )
*/
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 )
{

View file

@ -93,7 +93,7 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src )
{
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 @@ static int ssl_session_copy( ssl_session *dst, const ssl_session *src )
#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 @@ int ssl_parse_certificate( ssl_context *ssl )
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 @@ static int ssl_handshake_init( ssl_context *ssl )
*/
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 @@ int ssl_init( ssl_context *ssl )
/*
* 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 @@ int ssl_init( ssl_context *ssl )
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 @@ static int ssl_ticket_keys_init( ssl_context *ssl )
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 @@ static ssl_key_cert *ssl_add_key_cert( ssl_context *ssl )
{
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 @@ int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
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 @@ int ssl_set_own_cert_alt( ssl_context *ssl, x509_crt *own_cert,
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 @@ int ssl_set_psk( ssl_context *ssl, const unsigned char *psk, size_t psk_len,
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 @@ int ssl_set_hostname( ssl_context *ssl, const char *hostname )
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 );

View file

@ -451,7 +451,7 @@ int x509_get_name( unsigned char **p, const unsigned char *end,
/* 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 @@ int x509_get_name( unsigned char **p, const unsigned char *end,
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 );

View file

@ -279,7 +279,7 @@ int x509_crl_parse_der( x509_crl *chain,
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 )
{

View file

@ -359,7 +359,7 @@ static int x509_get_subject_alt_name( unsigned char **p,
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 @@ static int x509_crt_parse_der_core( x509_crt *crt, const unsigned char *buf,
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 @@ int x509_crt_parse_der( x509_crt *chain, const unsigned char *buf,
*/
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 );

View file

@ -112,7 +112,7 @@ int x509_csr_parse_der( x509_csr *csr,
/*
* 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 );

View file

@ -299,8 +299,8 @@ static int ssl_test( struct options *opt )
}
}
read_buf = (unsigned char *) polarssl_malloc( opt->buffer_size );
write_buf = (unsigned char *) polarssl_malloc( opt->buffer_size );
read_buf = polarssl_malloc( opt->buffer_size );
write_buf = polarssl_malloc( opt->buffer_size );
if( read_buf == NULL || write_buf == NULL )
{

View file

@ -136,7 +136,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
*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( -1 );