Prefer ASSERT_ALLOC to calloc+TEST_ASSERT in PSA tests

To allocate memory dynamically in a test, call ASSERT_ALLOC which
takes care of calling calloc and of checking for NULL.
This commit is contained in:
Gilles Peskine 2018-12-18 00:52:27 +01:00
parent 1f2aa0e3b0
commit d76f181617
2 changed files with 2 additions and 5 deletions

View file

@ -407,7 +407,6 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator,
public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( private_key_type );
public_key_length = PSA_KEY_EXPORT_MAX_SIZE( public_key_type, key_bits );
ASSERT_ALLOC( public_key, public_key_length );
TEST_ASSERT( public_key != NULL );
PSA_ASSERT( psa_export_public_key( handle,
public_key, public_key_length,
&public_key_length ) );

View file

@ -36,8 +36,7 @@ void load_data_from_file( int id_to_load_arg,
}
/* Read from the file with psa_crypto_storage_load. */
loaded_data = mbedtls_calloc( 1, capacity );
TEST_ASSERT( loaded_data != NULL );
ASSERT_ALLOC( loaded_data, capacity );
status = psa_crypto_storage_load( id_to_load, loaded_data, file_size );
/* Check we get the expected status. */
@ -82,8 +81,7 @@ void write_data_to_file( data_t *data, int expected_status )
TEST_EQUAL( file_size, data->len );
/* Check that the file contents are what we expect */
loaded_data = mbedtls_calloc( 1, data->len );
TEST_ASSERT( loaded_data != NULL );
ASSERT_ALLOC( loaded_data, data->len );
num_read = fread( loaded_data, 1, file_size, file );
TEST_EQUAL( num_read, file_size );