mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-31 01:20:35 +00:00
Add a do-while loop around macros
This is good practice in C. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
parent
cd70070c25
commit
690b8c9ca7
@ -53,13 +53,17 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CHECK(code) if ((ret = (code)) != 0) { return ret; }
|
#define CHECK(code) \
|
||||||
|
do { \
|
||||||
|
if ((ret = (code)) != 0) { \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define CHECK_RANGE(min, max, val) \
|
#define CHECK_RANGE(min, max, val) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
if ((val) < (min) || (val) > (max)) { \
|
||||||
if ((val) < (min) || (val) > (max)) \
|
return ret; \
|
||||||
{ \
|
|
||||||
return ret; \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -1700,16 +1704,19 @@ int mbedtls_x509_info_subject_alt_name(char **buf, size_t *size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRINT_ITEM(i) \
|
#define PRINT_ITEM(i) \
|
||||||
{ \
|
do { \
|
||||||
ret = mbedtls_snprintf(p, n, "%s" i, sep); \
|
ret = mbedtls_snprintf(p, n, "%s" i, sep); \
|
||||||
MBEDTLS_X509_SAFE_SNPRINTF; \
|
MBEDTLS_X509_SAFE_SNPRINTF; \
|
||||||
sep = ", "; \
|
sep = ", "; \
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
#define CERT_TYPE(type, name) \
|
#define CERT_TYPE(type, name) \
|
||||||
if (ns_cert_type & (type)) \
|
do { \
|
||||||
PRINT_ITEM(name);
|
if (ns_cert_type & (type)) { \
|
||||||
|
PRINT_ITEM(name); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int mbedtls_x509_info_cert_type(char **buf, size_t *size,
|
int mbedtls_x509_info_cert_type(char **buf, size_t *size,
|
||||||
unsigned char ns_cert_type)
|
unsigned char ns_cert_type)
|
||||||
@ -1734,9 +1741,12 @@ int mbedtls_x509_info_cert_type(char **buf, size_t *size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define KEY_USAGE(code, name) \
|
#define KEY_USAGE(code, name) \
|
||||||
if (key_usage & (code)) \
|
do { \
|
||||||
PRINT_ITEM(name);
|
if ((key_usage) & (code)) { \
|
||||||
|
PRINT_ITEM(name); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int mbedtls_x509_info_key_usage(char **buf, size_t *size,
|
int mbedtls_x509_info_key_usage(char **buf, size_t *size,
|
||||||
unsigned int key_usage)
|
unsigned int key_usage)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user