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.
* \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( 1 );
+}
static int exercise_mac_key( psa_key_slot_t key,
psa_key_usage_t usage,
@@ -349,7 +349,7 @@ 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,
+ TEST_ASSERT( mem_is_zero( exported + exported_length,
export_size - exported_length ) );
if( status != PSA_SUCCESS )
{
