From 09ffbfa045ea0ab41a46179d24eae1aa688c3527 Mon Sep 17 00:00:00 2001 From: Chris Cappuccio Date: Thu, 27 May 2021 20:54:16 -0700 Subject: [PATCH] Use _Static_assert in C code instead of static_assert --- src/core/configurator/cpipe.c | 2 +- src/core/message_base.h | 2 +- src/core/message_garbage.c | 2 +- src/core/message_ipfix.c | 4 ++-- src/core/message_session.c | 2 +- src/core/message_terminate.c | 4 ++-- src/core/netflow2ipfix/netflow5.c | 12 ++++++------ src/core/netflow2ipfix/netflow9.c | 6 +++--- src/core/odid_range.c | 4 ++-- src/plugins/input/tcp/tcp.c | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/configurator/cpipe.c b/src/core/configurator/cpipe.c index 53562a87..699f6981 100644 --- a/src/core/configurator/cpipe.c +++ b/src/core/configurator/cpipe.c @@ -27,7 +27,7 @@ static int cpipe_fd[2] = {INVALID_FD, INVALID_FD}; static const char *module = "Configuration pipe"; // Size of the request must allow atomic write! (see write() for help) -static_assert(sizeof(struct ipx_cpipe_req) <= PIPE_BUF, "non-atomic write!"); +_Static_assert(sizeof(struct ipx_cpipe_req) <= PIPE_BUF, "non-atomic write!"); int ipx_cpipe_init() diff --git a/src/core/message_base.h b/src/core/message_base.h index 9891bcdd..64384155 100644 --- a/src/core/message_base.h +++ b/src/core/message_base.h @@ -70,7 +70,7 @@ struct ipx_msg { unsigned int ref_cnt; }; // TODO: 64 bytes alignment -static_assert(offsetof(struct ipx_msg, type) == 0, +_Static_assert(offsetof(struct ipx_msg, type) == 0, "Message type must be the first element of each IPFIXcol message."); /** diff --git a/src/core/message_garbage.c b/src/core/message_garbage.c index 0919cacd..19e60fe1 100644 --- a/src/core/message_garbage.c +++ b/src/core/message_garbage.c @@ -68,7 +68,7 @@ struct ipx_msg_garbage { ipx_msg_garbage_cb object_destructor; }; -static_assert(offsetof(struct ipx_msg_garbage, msg_header.type) == 0, +_Static_assert(offsetof(struct ipx_msg_garbage, msg_header.type) == 0, "Message header must be the first element of each IPFIXcol message."); // Create a garbage message diff --git a/src/core/message_ipfix.c b/src/core/message_ipfix.c index fdaa30d5..e36051e7 100644 --- a/src/core/message_ipfix.c +++ b/src/core/message_ipfix.c @@ -49,7 +49,7 @@ #include // free // Check correctness of structure implementation -static_assert(offsetof(struct ipx_msg_ipfix, msg_header.type) == 0, +_Static_assert(offsetof(struct ipx_msg_ipfix, msg_header.type) == 0, "Message header must be the first element of each IPFIXcol message."); size_t @@ -190,4 +190,4 @@ ipx_msg_ipfix_add_drec_ref(struct ipx_msg_ipfix **msg_ref) const size_t offset = msg->rec_info.cnt_valid * msg->rec_info.rec_size; msg->rec_info.cnt_valid++; return ((struct ipx_ipfix_record *) (((uint8_t *) msg->recs) + offset)); -} \ No newline at end of file +} diff --git a/src/core/message_session.c b/src/core/message_session.c index 70a6e61f..47c0d6b9 100644 --- a/src/core/message_session.c +++ b/src/core/message_session.c @@ -62,7 +62,7 @@ struct ipx_msg_session { const struct ipx_session *session; }; -static_assert(offsetof(struct ipx_msg_session, msg_header.type) == 0, +_Static_assert(offsetof(struct ipx_msg_session, msg_header.type) == 0, "Message header must be the first element of each IPFIXcol message."); ipx_msg_session_t * diff --git a/src/core/message_terminate.c b/src/core/message_terminate.c index 6bc8b963..c2de8b1b 100644 --- a/src/core/message_terminate.c +++ b/src/core/message_terminate.c @@ -56,7 +56,7 @@ struct ipx_msg_terminate { enum ipx_msg_terminate_type type; }; -static_assert(offsetof(struct ipx_msg_terminate, msg_header.type) == 0, +_Static_assert(offsetof(struct ipx_msg_terminate, msg_header.type) == 0, "Message type must be the first element of each IPFIXcol message."); ipx_msg_terminate_t * @@ -84,4 +84,4 @@ enum ipx_msg_terminate_type ipx_msg_terminate_get_type(const ipx_msg_terminate_t *msg) { return msg->type; -} \ No newline at end of file +} diff --git a/src/core/netflow2ipfix/netflow5.c b/src/core/netflow2ipfix/netflow5.c index 0a74b720..030c6c15 100644 --- a/src/core/netflow2ipfix/netflow5.c +++ b/src/core/netflow2ipfix/netflow5.c @@ -24,8 +24,8 @@ #include "../verbose.h" // Simple static asserts to prevent unexpected structure modifications! -static_assert(IPX_NF5_MSG_HDR_LEN == 24U, "NetFlow v5 header size is not valid!"); -static_assert(IPX_NF5_MSG_REC_LEN == 48U, "NetFlow v5 record size is not valid!"); +_Static_assert(IPX_NF5_MSG_HDR_LEN == 24U, "NetFlow v5 header size is not valid!"); +_Static_assert(IPX_NF5_MSG_REC_LEN == 48U, "NetFlow v5 record size is not valid!"); /// Auxiliary definition to represent size of 1 byte #define BYTES_1 (1U) @@ -78,7 +78,7 @@ static const uint16_t nf5_tmpl_set[] = { /// Number of fields (including header fields) in the Template Set #define NF5_TSET_ITEMS (sizeof(nf5_tmpl_set) / sizeof(nf5_tmpl_set[0])) -static_assert(NF5_TSET_ITEMS % 2 == 0, "Number of fields MUST be even!"); +_Static_assert(NF5_TSET_ITEMS % 2 == 0, "Number of fields MUST be even!"); /** * @brief Structure of a NetFlow v5 record after convertion to IPFIX @@ -130,8 +130,8 @@ struct __attribute__((__packed__)) new_ipx_rec { /// Size of the second part to copy (without tailing padding) #define PART2_LEN (offsetof(struct ipx_nf5_rec, _pad2) - offsetof(struct ipx_nf5_rec, port_src)) -static_assert(PART1_LEN == offsetof(struct new_ipx_rec, ts_first), "Different Part 1 size"); -static_assert(PART2_LEN == +_Static_assert(PART1_LEN == offsetof(struct new_ipx_rec, ts_first), "Different Part 1 size"); +_Static_assert(PART2_LEN == offsetof(struct new_ipx_rec, sampling_alg) - offsetof(struct new_ipx_rec, port_src), "Different Part 2 size"); @@ -552,4 +552,4 @@ void ipx_nf5_conv_verb(ipx_nf5_conv_t *conv, enum ipx_verb_level v_new) { conv->conf.vlevel = v_new; -} \ No newline at end of file +} diff --git a/src/core/netflow2ipfix/netflow9.c b/src/core/netflow2ipfix/netflow9.c index 456bd0cc..ef607351 100644 --- a/src/core/netflow2ipfix/netflow9.c +++ b/src/core/netflow2ipfix/netflow9.c @@ -41,8 +41,8 @@ (UINT16_MAX - FDS_IPFIX_MSG_HDR_LEN - FDS_IPFIX_SET_HDR_LEN) // Simple static asserts to prevent unexpected structure modifications! -static_assert(IPX_NF9_MSG_HDR_LEN == 20U, "NetFlow v9 Message header size is not valid!"); -static_assert(IPX_NF9_SET_HDR_LEN == 4U, "NetFlow v9 Set header size is not valid!"); +_Static_assert(IPX_NF9_MSG_HDR_LEN == 20U, "NetFlow v9 Message header size is not valid!"); +_Static_assert(IPX_NF9_SET_HDR_LEN == 4U, "NetFlow v9 Set header size is not valid!"); /// Auxiliary conversion structure from NetFlow Options Field to IPFIX Inf. Element ID struct nf2ipx_opts { @@ -1274,4 +1274,4 @@ void ipx_nf9_conv_verb(ipx_nf9_conv_t *conv, enum ipx_verb_level v_new) { conv->vlevel = v_new; -} \ No newline at end of file +} diff --git a/src/core/odid_range.c b/src/core/odid_range.c index ea23e254..cc7d8347 100644 --- a/src/core/odid_range.c +++ b/src/core/odid_range.c @@ -146,7 +146,7 @@ range_is_empty(const char *str) static int range_str2uint32(const char *str, uint32_t *res) { - static_assert(ULONG_MAX >= UINT32_MAX, "Unsigned long is too small."); + _Static_assert(ULONG_MAX >= UINT32_MAX, "Unsigned long is too small."); errno = 0; char *end_ptr = NULL; @@ -433,4 +433,4 @@ ipx_orange_print(const ipx_orange_t *range) break; } } -} \ No newline at end of file +} diff --git a/src/plugins/input/tcp/tcp.c b/src/plugins/input/tcp/tcp.c index e501804f..54862749 100644 --- a/src/plugins/input/tcp/tcp.c +++ b/src/plugins/input/tcp/tcp.c @@ -824,7 +824,7 @@ socket_process(ipx_ctx_t *ctx, struct tcp_pair *pair) { const char *err_str; struct fds_ipfix_msg_hdr hdr; - static_assert(sizeof(hdr) == FDS_IPFIX_MSG_HDR_LEN, "Invalid size of IPFIX Message header"); + _Static_assert(sizeof(hdr) == FDS_IPFIX_MSG_HDR_LEN, "Invalid size of IPFIX Message header"); // Get the message header (do not move pointer) ssize_t len = recv(pair->fd, &hdr, FDS_IPFIX_MSG_HDR_LEN, MSG_WAITALL | MSG_PEEK); @@ -1026,4 +1026,4 @@ ipx_plugin_session_close(ipx_ctx_t *ctx, void *cfg, const struct ipx_session *se IPX_CTX_WARNING(ctx, "Received a request to close a unknown Transport Session!", '\0'); return; } -} \ No newline at end of file +}