From 2d88549c6b7549131ac1d2cf305d6cd5e1aa1853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 7 Jan 2020 10:17:35 +0100 Subject: [PATCH] Improve readability of macro in selftest --- library/sha512.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/sha512.c b/library/sha512.c index fbb034fac..67571c29e 100644 --- a/library/sha512.c +++ b/library/sha512.c @@ -587,9 +587,7 @@ static const unsigned char sha512_test_sum[][64] = 0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B } }; -#define SHA512_TEST_SUM_N \ - ( sizeof( sha512_test_sum ) / sizeof( sha512_test_sum[0] ) ) - +#define ARRAY_LEN(a) ( sizeof( a ) / sizeof( a[0] ) ) /* * Checkup routine @@ -612,7 +610,7 @@ int mbedtls_sha512_self_test( int verbose ) mbedtls_sha512_init( &ctx ); - for( i = 0; i < (int) SHA512_TEST_SUM_N; i++ ) + for( i = 0; i < (int) ARRAY_LEN(sha512_test_sum); i++ ) { j = i % 3; #if !defined(MBEDTLS_SHA512_NO_SHA384) @@ -675,6 +673,8 @@ exit: return( ret ); } +#undef ARRAY_LEN + #endif /* MBEDTLS_SELF_TEST */ #endif /* MBEDTLS_SHA512_C */