mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-24 12:25:40 +00:00
Simplify mem_is_nonzero to mem_is_zero
This also fixes a bug that the value that mem_is_nonzero tried to return could overflow int.
This commit is contained in:
parent
818ca1283a
commit
3f669c374a
|
@ -13,18 +13,18 @@
|
|||
* \param buffer Pointer to the beginning of the buffer.
|
||||
* \param size Size of the buffer in bytes.
|
||||
*
|
||||
* \return 0 if the buffer is all-bits-zero.
|
||||
* \return A nonzero value otherwise.
|
||||
* \return 1 if the buffer is all-bits-zero.
|
||||
* \return 0 if there is at least one nonzero byte.
|
||||
*/
|
||||
int mem_is_nonzero( void *buffer, size_t size )
|
||||
static int mem_is_zero( void *buffer, size_t size )
|
||||
{
|
||||
size_t i;
|
||||
for( i = 0; i < size; i++ )
|
||||
{
|
||||
if( ( (unsigned char *) buffer )[i] != 0 )
|
||||
return( i + 1 );
|
||||
return( 0 );
|
||||
}
|
||||
return( 0 );
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
static int exercise_mac_key( psa_key_slot_t key,
|
||||
|
@ -349,8 +349,8 @@ void import_export( data_t *data,
|
|||
exported, export_size,
|
||||
&exported_length );
|
||||
TEST_ASSERT( status == (psa_status_t) expected_export_status );
|
||||
TEST_ASSERT( ! mem_is_nonzero( exported + exported_length,
|
||||
export_size - exported_length ) );
|
||||
TEST_ASSERT( mem_is_zero( exported + exported_length,
|
||||
export_size - exported_length ) );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
TEST_ASSERT( exported_length == 0 );
|
||||
|
|
Loading…
Reference in a new issue