Commit 7551cb9e authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard
Browse files

Replace malloc with calloc

- platform layer currently broken (not adapted yet)
- memmory_buffer_alloc too
parent 065122cf
...@@ -1986,7 +1986,7 @@ ...@@ -1986,7 +1986,7 @@
* *
* This module enables abstraction of common (libc) functions. * This module enables abstraction of common (libc) functions.
*/ */
#define MBEDTLS_PLATFORM_C //#define MBEDTLS_PLATFORM_C
/** /**
* \def MBEDTLS_RIPEMD160_C * \def MBEDTLS_RIPEMD160_C
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -270,7 +270,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p, ...@@ -270,7 +270,7 @@ int mbedtls_asn1_get_sequence_of( unsigned char **p,
/* Allocate and assign next pointer */ /* Allocate and assign next pointer */
if( *p < end ) if( *p < end )
{ {
cur->next = mbedtls_malloc( sizeof( mbedtls_asn1_sequence ) ); cur->next = mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) );
if( cur->next == NULL ) if( cur->next == NULL )
return( MBEDTLS_ERR_ASN1_MALLOC_FAILED ); return( MBEDTLS_ERR_ASN1_MALLOC_FAILED );
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -313,13 +313,13 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data ...@@ -313,13 +313,13 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
{ {
// Add new entry if not present yet based on OID // Add new entry if not present yet based on OID
// //
if( ( cur = mbedtls_malloc( sizeof(mbedtls_asn1_named_data) ) ) == NULL ) if( ( cur = mbedtls_calloc( 1, sizeof(mbedtls_asn1_named_data) ) ) == NULL )
return( NULL ); return( NULL );
memset( cur, 0, sizeof(mbedtls_asn1_named_data) ); memset( cur, 0, sizeof(mbedtls_asn1_named_data) );
cur->oid.len = oid_len; cur->oid.len = oid_len;
cur->oid.p = mbedtls_malloc( oid_len ); cur->oid.p = mbedtls_calloc( 1, oid_len );
if( cur->oid.p == NULL ) if( cur->oid.p == NULL )
{ {
mbedtls_free( cur ); mbedtls_free( cur );
...@@ -329,7 +329,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data ...@@ -329,7 +329,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
memcpy( cur->oid.p, oid, oid_len ); memcpy( cur->oid.p, oid, oid_len );
cur->val.len = val_len; cur->val.len = val_len;
cur->val.p = mbedtls_malloc( val_len ); cur->val.p = mbedtls_calloc( 1, val_len );
if( cur->val.p == NULL ) if( cur->val.p == NULL )
{ {
mbedtls_free( cur->oid.p ); mbedtls_free( cur->oid.p );
...@@ -348,7 +348,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data ...@@ -348,7 +348,7 @@ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data
cur->val.p = NULL; cur->val.p = NULL;
cur->val.len = val_len; cur->val.len = val_len;
cur->val.p = mbedtls_malloc( val_len ); cur->val.p = mbedtls_calloc( 1, val_len );
if( cur->val.p == NULL ) if( cur->val.p == NULL )
{ {
mbedtls_free( cur->oid.p ); mbedtls_free( cur->oid.p );
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_printf printf #define mbedtls_printf printf
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -109,11 +109,9 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ) ...@@ -109,11 +109,9 @@ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs )
if( X->n < nblimbs ) if( X->n < nblimbs )
{ {
if( ( p = mbedtls_malloc( nblimbs * ciL ) ) == NULL ) if( ( p = mbedtls_calloc( nblimbs, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_MALLOC_FAILED ); return( MBEDTLS_ERR_MPI_MALLOC_FAILED );
memset( p, 0, nblimbs * ciL );
if( X->p != NULL ) if( X->p != NULL )
{ {
memcpy( p, X->p, X->n * ciL ); memcpy( p, X->p, X->n * ciL );
...@@ -149,11 +147,9 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ) ...@@ -149,11 +147,9 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
if( i < nblimbs ) if( i < nblimbs )
i = nblimbs; i = nblimbs;
if( ( p = mbedtls_malloc( i * ciL ) ) == NULL ) if( ( p = mbedtls_calloc( i, ciL ) ) == NULL )
return( MBEDTLS_ERR_MPI_MALLOC_FAILED ); return( MBEDTLS_ERR_MPI_MALLOC_FAILED );
memset( p, 0, i * ciL );
if( X->p != NULL ) if( X->p != NULL )
{ {
memcpy( p, X->p, i * ciL ); memcpy( p, X->p, i * ciL );
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
/* shared by all GCM ciphers */ /* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void ) static void *gcm_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_gcm_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
} }
static void gcm_ctx_free( void *ctx ) static void gcm_ctx_free( void *ctx )
...@@ -92,7 +92,7 @@ static void gcm_ctx_free( void *ctx ) ...@@ -92,7 +92,7 @@ static void gcm_ctx_free( void *ctx )
/* shared by all CCM ciphers */ /* shared by all CCM ciphers */
static void *ccm_ctx_alloc( void ) static void *ccm_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_ccm_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
} }
static void ccm_ctx_free( void *ctx ) static void ccm_ctx_free( void *ctx )
...@@ -153,7 +153,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, ...@@ -153,7 +153,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * aes_ctx_alloc( void ) static void * aes_ctx_alloc( void )
{ {
mbedtls_aes_context *aes = mbedtls_malloc( sizeof( mbedtls_aes_context ) ); mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
if( aes == NULL ) if( aes == NULL )
return( NULL ); return( NULL );
...@@ -510,7 +510,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, ...@@ -510,7 +510,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * camellia_ctx_alloc( void ) static void * camellia_ctx_alloc( void )
{ {
mbedtls_camellia_context *ctx; mbedtls_camellia_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_camellia_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
...@@ -897,7 +897,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, ...@@ -897,7 +897,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
static void * des_ctx_alloc( void ) static void * des_ctx_alloc( void )
{ {
mbedtls_des_context *des = mbedtls_malloc( sizeof( mbedtls_des_context ) ); mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
if( des == NULL ) if( des == NULL )
return( NULL ); return( NULL );
...@@ -916,7 +916,7 @@ static void des_ctx_free( void *ctx ) ...@@ -916,7 +916,7 @@ static void des_ctx_free( void *ctx )
static void * des3_ctx_alloc( void ) static void * des3_ctx_alloc( void )
{ {
mbedtls_des3_context *des3; mbedtls_des3_context *des3;
des3 = mbedtls_malloc( sizeof( mbedtls_des3_context ) ); des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
if( des3 == NULL ) if( des3 == NULL )
return( NULL ); return( NULL );
...@@ -1115,7 +1115,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, ...@@ -1115,7 +1115,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
static void * blowfish_ctx_alloc( void ) static void * blowfish_ctx_alloc( void )
{ {
mbedtls_blowfish_context *ctx; mbedtls_blowfish_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_blowfish_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
...@@ -1225,7 +1225,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key, ...@@ -1225,7 +1225,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
static void * arc4_ctx_alloc( void ) static void * arc4_ctx_alloc( void )
{ {
mbedtls_arc4_context *ctx; mbedtls_arc4_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_arc4_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#define mbedtls_printf printf #define mbedtls_printf printf
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -531,7 +531,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) ...@@ -531,7 +531,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n )
*n = (size_t) size; *n = (size_t) size;
if( *n + 1 == 0 || if( *n + 1 == 0 ||
( *buf = mbedtls_malloc( *n + 1 ) ) == NULL ) ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL )
{ {
fclose( f ); fclose( f );
return( MBEDTLS_ERR_DHM_MALLOC_FAILED ); return( MBEDTLS_ERR_DHM_MALLOC_FAILED );
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#define mbedtls_printf printf #define mbedtls_printf printf
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -790,12 +790,10 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp, ...@@ -790,12 +790,10 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
if( t_len < 2 ) if( t_len < 2 )
return( ecp_normalize_jac( grp, *T ) ); return( ecp_normalize_jac( grp, *T ) );
if( ( c = mbedtls_malloc( t_len * sizeof( mbedtls_mpi ) ) ) == NULL ) if( ( c = mbedtls_calloc( t_len, sizeof( mbedtls_mpi ) ) ) == NULL )
return( MBEDTLS_ERR_ECP_MALLOC_FAILED ); return( MBEDTLS_ERR_ECP_MALLOC_FAILED );
mbedtls_mpi_init( &u ); mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi ); mbedtls_mpi_init( &u ); mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi );
for( i = 0; i < t_len; i++ )
mbedtls_mpi_init( &c[i] );
/* /*
* c[i] = Z_0 * ... * Z_i * c[i] = Z_0 * ... * Z_i
...@@ -1363,16 +1361,13 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ...@@ -1363,16 +1361,13 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
if( T == NULL ) if( T == NULL )
{ {
T = mbedtls_malloc( pre_len * sizeof( mbedtls_ecp_point ) ); T = mbedtls_calloc( pre_len, sizeof( mbedtls_ecp_point ) );
if( T == NULL ) if( T == NULL )
{ {
ret = MBEDTLS_ERR_ECP_MALLOC_FAILED; ret = MBEDTLS_ERR_ECP_MALLOC_FAILED;
goto cleanup; goto cleanup;
} }
for( i = 0; i < pre_len; i++ )
mbedtls_ecp_point_init( &T[i] );
MBEDTLS_MPI_CHK( ecp_precompute_comb( grp, T, P, w, d ) ); MBEDTLS_MPI_CHK( ecp_precompute_comb( grp, T, P, w, d ) );
if( p_eq_g ) if( p_eq_g )
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -216,7 +216,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf ...@@ -216,7 +216,7 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf
if( hmac != 0 ) if( hmac != 0 )
{ {
ctx->hmac_ctx = mbedtls_malloc( 2 * md_info->block_size ); ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size );
if( ctx->hmac_ctx == NULL ) if( ctx->hmac_ctx == NULL )
{ {
md_info->ctx_free_func( ctx->md_ctx ); md_info->ctx_free_func( ctx->md_ctx );
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc
#define mbedtls_free free #define mbedtls_free free
#endif #endif
...@@ -106,7 +106,7 @@ static int md2_file_wrap( const char *path, unsigned char *output ) ...@@ -106,7 +106,7 @@ static int md2_file_wrap( const char *path, unsigned char *output )
static void * md2_ctx_alloc( void ) static void * md2_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_md2_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
} }
static void md2_ctx_free( void *ctx ) static void md2_ctx_free( void *ctx )
...@@ -170,7 +170,7 @@ static int md4_file_wrap( const char *path, unsigned char *output ) ...@@ -170,7 +170,7 @@ static int md4_file_wrap( const char *path, unsigned char *output )
static void *md4_ctx_alloc( void ) static void *md4_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_md4_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
} }
static void md4_ctx_free( void *ctx ) static void md4_ctx_free( void *ctx )
...@@ -232,7 +232,7 @@ static int md5_file_wrap( const char *path, unsigned char *output ) ...@@ -232,7 +232,7 @@ static int md5_file_wrap( const char *path, unsigned char *output )
static void * md5_ctx_alloc( void ) static void * md5_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_md5_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
} }
static void md5_ctx_free( void *ctx ) static void md5_ctx_free( void *ctx )
...@@ -295,7 +295,7 @@ static int ripemd160_file_wrap( const char *path, unsigned char *output ) ...@@ -295,7 +295,7 @@ static int ripemd160_file_wrap( const char *path, unsigned char *output )
static void * ripemd160_ctx_alloc( void ) static void * ripemd160_ctx_alloc( void )
{ {
mbedtls_ripemd160_context *ctx; mbedtls_ripemd160_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_ripemd160_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
...@@ -365,7 +365,7 @@ static int sha1_file_wrap( const char *path, unsigned char *output ) ...@@ -365,7 +365,7 @@ static int sha1_file_wrap( const char *path, unsigned char *output )
static void * sha1_ctx_alloc( void ) static void * sha1_ctx_alloc( void )
{ {
mbedtls_sha1_context *ctx; mbedtls_sha1_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_sha1_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
...@@ -443,7 +443,7 @@ static int sha224_file_wrap( const char *path, unsigned char *output ) ...@@ -443,7 +443,7 @@ static int sha224_file_wrap( const char *path, unsigned char *output )
static void * sha224_ctx_alloc( void ) static void * sha224_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_sha256_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
} }
static void sha224_ctx_free( void *ctx ) static void sha224_ctx_free( void *ctx )
...@@ -508,7 +508,7 @@ static int sha256_file_wrap( const char *path, unsigned char *output ) ...@@ -508,7 +508,7 @@ static int sha256_file_wrap( const char *path, unsigned char *output )
static void * sha256_ctx_alloc( void ) static void * sha256_ctx_alloc( void )
{ {
mbedtls_sha256_context *ctx; mbedtls_sha256_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_sha256_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
...@@ -583,7 +583,7 @@ static int sha384_file_wrap( const char *path, unsigned char *output ) ...@@ -583,7 +583,7 @@ static int sha384_file_wrap( const char *path, unsigned char *output )
static void * sha384_ctx_alloc( void ) static void * sha384_ctx_alloc( void )
{ {
return mbedtls_malloc( sizeof( mbedtls_sha512_context ) ); return mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
} }
static void sha384_ctx_free( void *ctx ) static void sha384_ctx_free( void *ctx )
...@@ -648,7 +648,7 @@ static int sha512_file_wrap( const char *path, unsigned char *output ) ...@@ -648,7 +648,7 @@ static int sha512_file_wrap( const char *path, unsigned char *output )
static void * sha512_ctx_alloc( void ) static void * sha512_ctx_alloc( void )
{ {
mbedtls_sha512_context *ctx; mbedtls_sha512_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_sha512_context ) ); ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
if( ctx == NULL ) if( ctx == NULL )
return( NULL ); return( NULL );
......
...@@ -649,9 +649,9 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose ) ...@@ -649,9 +649,9 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose )
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) ); mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
p = mbedtls_malloc( 1 ); p = mbedtls_calloc( 1, 1 );
q = mbedtls_malloc( 128 ); q = mbedtls_calloc( 1, 128 );
r = mbedtls_malloc( 16 ); r = mbedtls_calloc( 1, 16 );
TEST_ASSERT( check_pointer( p ) == 0 && TEST_ASSERT( check_pointer( p ) == 0 &&
check_pointer( q ) == 0 && check_pointer( q ) == 0 &&
...@@ -678,9 +678,9 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose ) ...@@ -678,9 +678,9 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose )
TEST_ASSERT( heap.buf + heap.len == end ); TEST_ASSERT( heap.buf + heap.len == end );
p = mbedtls_malloc( 1 ); p = mbedtls_calloc( 1, 1 );
q = mbedtls_malloc( 128 ); q = mbedtls_calloc( 1, 128 );
r = mbedtls_malloc( 16 ); r = mbedtls_calloc( 1, 16 );
TEST_ASSERT( check_pointer( p ) == 0 && TEST_ASSERT( check_pointer( p ) == 0 &&
check_pointer( q ) == 0 && check_pointer( q ) == 0 &&
...@@ -702,22 +702,22 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose ) ...@@ -702,22 +702,22 @@ int mbedtls_memory_buffer_alloc_self_test( int verbose )
mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) ); mbedtls_memory_buffer_alloc_init( buf, sizeof( buf ) );
p = mbedtls_malloc( sizeof( buf ) - sizeof( memory_header ) ); p = mbedtls_calloc( 1, sizeof( buf ) - sizeof( memory_header ) );
TEST_ASSERT( check_pointer( p ) == 0 ); TEST_ASSERT( check_pointer( p ) == 0 );
TEST_ASSERT( mbedtls_malloc( 1 ) == NULL ); TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
mbedtls_free( p ); mbedtls_free( p );
p = mbedtls_malloc( sizeof( buf ) - 2 * sizeof( memory_header ) - 16 ); p = mbedtls_calloc( 1, sizeof( buf ) - 2 * sizeof( memory_header ) - 16 );
q = mbedtls_malloc( 16 ); q = mbedtls_calloc( 1, 16 );
TEST_ASSERT( check_pointer( p ) == 0 && check_pointer( q ) == 0 ); TEST_ASSERT( check_pointer( p ) == 0 && check_pointer( q ) == 0 );
TEST_ASSERT( mbedtls_malloc( 1 ) == NULL ); TEST_ASSERT( mbedtls_calloc( 1, 1 ) == NULL );
mbedtls_free( q ); mbedtls_free( q );
TEST_ASSERT( mbedtls_malloc( 17 ) == NULL ); TEST_ASSERT( mbedtls_calloc( 1, 17 ) == NULL );
mbedtls_free( p ); mbedtls_free( p );
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdlib.h> #include <stdlib.h>
#define mbedtls_malloc malloc #define mbedtls_calloc calloc