mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Improve macro hygiene
This commit improves hygiene and formatting of macro definitions throughout the library. Specifically: - It adds brackets around parameters to avoid unintended interpretation of arguments, e.g. due to operator precedence. - It adds uses of the `do { ... } while( 0 )` idiom for macros that can be used as commands.
This commit is contained in:
committed by
Simon Butcher
parent
9c99dc862c
commit
1eeca41472
@ -615,11 +615,14 @@ static int get_auth_mode( const char *s )
|
||||
* Used by sni_parse and psk_parse to handle coma-separated lists
|
||||
*/
|
||||
#define GET_ITEM( dst ) \
|
||||
dst = p; \
|
||||
while( *p != ',' ) \
|
||||
if( ++p > end ) \
|
||||
goto error; \
|
||||
*p++ = '\0';
|
||||
do \
|
||||
{ \
|
||||
(dst) = p; \
|
||||
while( *p != ',' ) \
|
||||
if( ++p > end ) \
|
||||
goto error; \
|
||||
*p++ = '\0'; \
|
||||
} while( 0 )
|
||||
|
||||
#if defined(SNI_OPTION)
|
||||
typedef struct _sni_entry sni_entry;
|
||||
@ -776,15 +779,18 @@ int sni_callback( void *p_info, mbedtls_ssl_context *ssl,
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
|
||||
|
||||
#define HEX2NUM( c ) \
|
||||
if( c >= '0' && c <= '9' ) \
|
||||
c -= '0'; \
|
||||
else if( c >= 'a' && c <= 'f' ) \
|
||||
c -= 'a' - 10; \
|
||||
else if( c >= 'A' && c <= 'F' ) \
|
||||
c -= 'A' - 10; \
|
||||
else \
|
||||
return( -1 );
|
||||
#define HEX2NUM( c ) \
|
||||
do \
|
||||
{ \
|
||||
if( (c) >= '0' && (c) <= '9' ) \
|
||||
(c) -= '0'; \
|
||||
else if( (c) >= 'a' && (c) <= 'f' ) \
|
||||
(c) -= 'a' - 10; \
|
||||
else if( (c) >= 'A' && (c) <= 'F' ) \
|
||||
(c) -= 'A' - 10; \
|
||||
else \
|
||||
return( -1 ); \
|
||||
} while( 0 )
|
||||
|
||||
/*
|
||||
* Convert a hex string to bytes.
|
||||
|
@ -163,7 +163,7 @@ do { \
|
||||
|
||||
#define MEMORY_MEASURE_PRINT( title_len ) \
|
||||
mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
|
||||
for( ii = 12 - title_len; ii != 0; ii-- ) mbedtls_printf( " " ); \
|
||||
for( ii = 12 - (title_len); ii != 0; ii-- ) mbedtls_printf( " " ); \
|
||||
max_used -= prv_used; \
|
||||
max_blocks -= prv_blocks; \
|
||||
max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
|
||||
|
Reference in New Issue
Block a user