git: 69945c49fea7 - main - netlink: Don't use a zero-length array
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 27 Feb 2024 20:00:07 UTC
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=69945c49fea7ac2352c1fd7d22f70f2e3861ba81
commit 69945c49fea7ac2352c1fd7d22f70f2e3861ba81
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-02-27 19:59:52 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-02-27 19:59:52 +0000
netlink: Don't use a zero-length array
Define SNL_DECLARE_FIELD_PARSER* macros to create a parser that has
no output attributes only input fields and use this to define the
snl_donemsg_parser.
This removes the need for the zero-length nla_p_donemsg[] variable.
Zero length arrays are not valid in ISO C.
Reviewed by: jrtc27, melifaro
Differential Revision: https://reviews.freebsd.org/D43918
---
sys/netlink/netlink_snl.h | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h
index 6636d53f2353..89ba5b5aef5d 100644
--- a/sys/netlink/netlink_snl.h
+++ b/sys/netlink/netlink_snl.h
@@ -174,6 +174,18 @@ static const struct snl_hdr_parser _name = { \
#define SNL_DECLARE_PARSER(_name, _t, _fp, _np) \
SNL_DECLARE_PARSER_EXT(_name, sizeof(_t), 0, _fp, _np, NULL)
+#define SNL_DECLARE_FIELD_PARSER_EXT(_name, _sz_h_in, _sz_out, _fp, _cb) \
+static const struct snl_hdr_parser _name = { \
+ .in_hdr_size = _sz_h_in, \
+ .out_size = _sz_out, \
+ .fp = &((_fp)[0]), \
+ .fp_size = NL_ARRAY_LEN(_fp), \
+ .cb_post = _cb, \
+}
+
+#define SNL_DECLARE_FIELD_PARSER(_name, _t, _fp) \
+ SNL_DECLARE_FIELD_PARSER_EXT(_name, sizeof(_t), 0, _fp, NULL)
+
#define SNL_DECLARE_ATTR_PARSER_EXT(_name, _sz_out, _np, _cb) \
static const struct snl_hdr_parser _name = { \
.out_size = _sz_out, \
@@ -921,14 +933,12 @@ SNL_DECLARE_PARSER(snl_errmsg_parser, struct nlmsgerr, nlf_p_errmsg, nla_p_errms
#define _IN(_field) offsetof(struct nlmsgerr, _field)
#define _OUT(_field) offsetof(struct snl_errmsg_data, _field)
-static const struct snl_attr_parser nla_p_donemsg[] = {};
-
static const struct snl_field_parser nlf_p_donemsg[] = {
{ .off_in = _IN(error), .off_out = _OUT(error), .cb = snl_field_get_uint32 },
};
#undef _IN
#undef _OUT
-SNL_DECLARE_PARSER(snl_donemsg_parser, struct nlmsgerr, nlf_p_donemsg, nla_p_donemsg);
+SNL_DECLARE_FIELD_PARSER(snl_donemsg_parser, struct nlmsgerr, nlf_p_donemsg);
static inline bool
snl_parse_errmsg(struct snl_state *ss, struct nlmsghdr *hdr, struct snl_errmsg_data *e)