Remove a few redundant memset after calloc.
Using the following semantic patch provided by Mansour Moufid:
@@
expression x;
@@
x = mbedtls_calloc(...)
...
- memset(x, 0, ...);
diff --git a/ChangeLog b/ChangeLog
index f667418..5ed8025 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -66,6 +66,7 @@
* Signature of mpi_mul_mpi() changed to make the last argument unsigned
* calloc() is now used instead of malloc() everywhere. API of platform
layer and the memory_buffer_alloc module changed accordingly.
+ (Thanks to Mansour Moufid for helping with the replacement.)
* Change SSL_DISABLE_RENEGOTIATION config.h flag to SSL_RENEGOTIATION
(support for renegotiation now needs explicit enabling in config.h).
* net_connect() and net_bind() have a new 'proto' argument to choose
diff --git a/library/asn1parse.c b/library/asn1parse.c
index ae392bb..563e9a7 100644
--- a/library/asn1parse.c
+++ b/library/asn1parse.c
@@ -275,8 +275,6 @@
if( cur->next == NULL )
return( MBEDTLS_ERR_ASN1_MALLOC_FAILED );
- memset( cur->next, 0, sizeof( mbedtls_asn1_sequence ) );
-
cur = cur->next;
}
}
diff --git a/library/asn1write.c b/library/asn1write.c
index 7862961..f5b1849 100644
--- a/library/asn1write.c
+++ b/library/asn1write.c
@@ -316,8 +316,6 @@
if( ( cur = mbedtls_calloc( 1, sizeof(mbedtls_asn1_named_data) ) ) == NULL )
return( NULL );
- memset( cur, 0, sizeof(mbedtls_asn1_named_data) );
-
cur->oid.len = oid_len;
cur->oid.p = mbedtls_calloc( 1, oid_len );
if( cur->oid.p == NULL )
diff --git a/library/ssl_cache.c b/library/ssl_cache.c
index 6a20cd3..e05bd88 100644
--- a/library/ssl_cache.c
+++ b/library/ssl_cache.c
@@ -229,8 +229,6 @@
goto exit;
}
- memset( cur, 0, sizeof(mbedtls_ssl_cache_entry) );
-
if( prv == NULL )
cache->chain = cur;
else
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index fa4d39e..76c644b 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -2931,8 +2931,6 @@
return( MBEDTLS_ERR_SSL_MALLOC_FAILED );
}
- memset( ssl->handshake->hs_msg, 0, alloc_len );
-
/* Prepare final header: copy msg_type, length and message_seq,
* then add standardised fragment_offset and fragment_length */
memcpy( ssl->handshake->hs_msg, ssl->in_msg, 6 );
@@ -5011,9 +5009,6 @@
return( MBEDTLS_ERR_SSL_MALLOC_FAILED );
}
- memset( ssl-> in_buf, 0, len );
- memset( ssl->out_buf, 0, len );
-
#if defined(MBEDTLS_SSL_PROTO_DTLS)
if( conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
{
diff --git a/library/x509.c b/library/x509.c
index 3cddc5f..0e998fc 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -457,8 +457,6 @@
if( cur->next == NULL )
return( MBEDTLS_ERR_X509_MALLOC_FAILED );
- memset( cur->next, 0, sizeof( mbedtls_x509_name ) );
-
cur = cur->next;
}
@@ -473,8 +471,6 @@
if( cur->next == NULL )
return( MBEDTLS_ERR_X509_MALLOC_FAILED );
- memset( cur->next, 0, sizeof( mbedtls_x509_name ) );
-
cur = cur->next;
}
}
diff --git a/library/x509_crl.c b/library/x509_crl.c
index 5c2c7d5..62d0a30 100644
--- a/library/x509_crl.c
+++ b/library/x509_crl.c
@@ -243,7 +243,6 @@
if( cur_entry->next == NULL )
return( MBEDTLS_ERR_X509_MALLOC_FAILED );
- memset( cur_entry->next, 0, sizeof( mbedtls_x509_crl_entry ) );
cur_entry = cur_entry->next;
}
}
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 849ea7b..d1749b9 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -365,7 +365,6 @@
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS +
MBEDTLS_ERR_ASN1_MALLOC_FAILED );
- memset( cur->next, 0, sizeof( mbedtls_asn1_sequence ) );
cur = cur->next;
}