Date: Mon, 29 Jun 2026 19:25:49 +0000 From: Olivier Certner <olce@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: bef2b6e3bf4a - stable/15 - MAC/do: clone_rules(): Readability improvements, constification Message-ID: <6a42c6bd.21e84.3e7edf98@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=bef2b6e3bf4a8e615438c4f90472fd70309a407c commit bef2b6e3bf4a8e615438c4f90472fd70309a407c Author: Olivier Certner <olce@FreeBSD.org> AuthorDate: 2026-05-20 10:33:41 +0000 Commit: Olivier Certner <olce@FreeBSD.org> CommitDate: 2026-06-29 19:23:46 +0000 MAC/do: clone_rules(): Readability improvements, constification Constify in order to let the compiler check that source and destination arguments are passed in the proper order in the different calls. No functional change (intended). Reviewed by: bapt MFC after: 1 month Sponsored by: The FreeBSD Foundation Pull Request: https://ron-dev.freebsd.org/FreeBSD/src/pulls/38 (cherry picked from commit ce59a4181593f59028d3a26f2b63dcf2c8041d79) --- sys/security/mac_do/mac_do.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index f23509f6bebe..7b9c45eb265b 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -1372,27 +1372,29 @@ set_default_conf(struct prison *const pr) static void clone_rules(struct rules *const dst, const struct rules *const src) { - struct rule *src_rule, *dst_rule; + const struct rule *src_rule; strlcpy(dst->string, src->string, sizeof(dst->string)); STAILQ_FOREACH(src_rule, &src->head, r_entries) { - dst_rule = malloc(sizeof(*dst_rule), M_MAC_DO, M_WAITOK | - M_ZERO); + struct rule *const dst_rule = malloc(sizeof(*dst_rule), + M_MAC_DO, M_WAITOK); bcopy(src_rule, dst_rule, sizeof(*dst_rule)); if (src_rule->uids_nb > 0) { - dst_rule->uids = malloc(sizeof(*dst_rule->uids) * - src_rule->uids_nb, M_MAC_DO, M_WAITOK); - bcopy(src_rule->uids, dst_rule->uids, - sizeof(*dst_rule->uids) * src_rule->uids_nb); + const size_t uids_size = sizeof(*dst_rule->uids) * + src_rule->uids_nb; + + dst_rule->uids = malloc(uids_size, M_MAC_DO, M_WAITOK); + bcopy(src_rule->uids, dst_rule->uids, uids_size); } if (src_rule->gids_nb > 0) { - dst_rule->gids = malloc(sizeof(*dst_rule->gids) * - src_rule->gids_nb, M_MAC_DO, M_WAITOK); - bcopy(src_rule->gids, dst_rule->gids, - sizeof(*dst_rule->gids) * src_rule->gids_nb); + const size_t gids_size = sizeof(*dst_rule->gids) * + src_rule->gids_nb; + + dst_rule->gids = malloc(gids_size, M_MAC_DO, M_WAITOK); + bcopy(src_rule->gids, dst_rule->gids, gids_size); } STAILQ_INSERT_TAIL(&dst->head, dst_rule, r_entries);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a42c6bd.21e84.3e7edf98>
