mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +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
@ -60,14 +60,14 @@
|
||||
MBEDTLS_INTERNAL_VALIDATE( cond )
|
||||
|
||||
#define BYTES_TO_U32_LE( data, offset ) \
|
||||
( (uint32_t) data[offset] \
|
||||
| (uint32_t) ( (uint32_t) data[( offset ) + 1] << 8 ) \
|
||||
| (uint32_t) ( (uint32_t) data[( offset ) + 2] << 16 ) \
|
||||
| (uint32_t) ( (uint32_t) data[( offset ) + 3] << 24 ) \
|
||||
( (uint32_t) (data)[offset] \
|
||||
| (uint32_t) ( (uint32_t) (data)[( offset ) + 1] << 8 ) \
|
||||
| (uint32_t) ( (uint32_t) (data)[( offset ) + 2] << 16 ) \
|
||||
| (uint32_t) ( (uint32_t) (data)[( offset ) + 3] << 24 ) \
|
||||
)
|
||||
|
||||
#define ROTL32( value, amount ) \
|
||||
( (uint32_t) ( value << amount ) | ( value >> ( 32 - amount ) ) )
|
||||
( (uint32_t) ( (value) << (amount) ) | ( (value) >> ( 32 - (amount) ) ) )
|
||||
|
||||
#define CHACHA20_CTR_INDEX ( 12U )
|
||||
|
||||
|
Reference in New Issue
Block a user