Skip to content

Commit d76f181

Browse files
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.
1 parent 1f2aa0e commit d76f181

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator,
407407
public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR( private_key_type );
408408
public_key_length = PSA_KEY_EXPORT_MAX_SIZE( public_key_type, key_bits );
409409
ASSERT_ALLOC( public_key, public_key_length );
410-
TEST_ASSERT( public_key != NULL );
411410
PSA_ASSERT( psa_export_public_key( handle,
412411
public_key, public_key_length,
413412
&public_key_length ) );

tests/suites/test_suite_psa_crypto_storage_file.function

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ void load_data_from_file( int id_to_load_arg,
3636
}
3737

3838
/* Read from the file with psa_crypto_storage_load. */
39-
loaded_data = mbedtls_calloc( 1, capacity );
40-
TEST_ASSERT( loaded_data != NULL );
39+
ASSERT_ALLOC( loaded_data, capacity );
4140
status = psa_crypto_storage_load( id_to_load, loaded_data, file_size );
4241

4342
/* Check we get the expected status. */
@@ -82,8 +81,7 @@ void write_data_to_file( data_t *data, int expected_status )
8281
TEST_EQUAL( file_size, data->len );
8382

8483
/* Check that the file contents are what we expect */
85-
loaded_data = mbedtls_calloc( 1, data->len );
86-
TEST_ASSERT( loaded_data != NULL );
84+
ASSERT_ALLOC( loaded_data, data->len );
8785

8886
num_read = fread( loaded_data, 1, file_size, file );
8987
TEST_EQUAL( num_read, file_size );

0 commit comments

Comments
 (0)