git: c3c816173d25 - main - ipfw: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])

From: Warner Losh <imp_at_FreeBSD.org>
Date: Mon, 29 Apr 2024 04:27:28 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=c3c816173d25fcb908a94c34b75fca98c5860f18

commit c3c816173d25fcb908a94c34b75fca98c5860f18
Author:     Elyes Haouas <ehaouas@noos.fr>
AuthorDate: 2023-11-07 17:36:35 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-29 03:30:55 +0000

    ipfw: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
    
    Pull Request: https://github.com/freebsd/freebsd-src/pull/888
    Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
---
 sbin/ipfw/dummynet.c | 4 ++--
 sbin/ipfw/ipfw2.c    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sbin/ipfw/dummynet.c b/sbin/ipfw/dummynet.c
index 9663e983b31a..6714b2af3124 100644
--- a/sbin/ipfw/dummynet.c
+++ b/sbin/ipfw/dummynet.c
@@ -22,7 +22,7 @@
 
 #define NEW_AQM
 #include <sys/limits.h>
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 /* XXX there are several sysctl leftover here */
 #include <sys/sysctl.h>
@@ -1401,7 +1401,7 @@ ipfw_config_pipe(int ac, char **av)
 	 */
 	if (p)
 		p->bandwidth = -1;
-	for (j = 0; j < sizeof(fs->par)/sizeof(fs->par[0]); j++)
+	for (j = 0; j < nitems(fs->par); j++)
 		fs->par[j] = -1;
 	while (ac > 0) {
 		double d;
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 72927e336fa8..51eae7e8e246 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -4035,8 +4035,8 @@ compile_rule(char *av[], uint32_t *rbuf, int *rbufsize, struct tidx *tstate)
 
 	rblen = *rbufsize / sizeof(uint32_t);
 	rblen -= sizeof(struct ip_fw_rule) / sizeof(uint32_t);
-	ablen = sizeof(actbuf) / sizeof(actbuf[0]);
-	cblen = sizeof(cmdbuf) / sizeof(cmdbuf[0]);
+	ablen = nitems(actbuf);
+	cblen = nitems(cmdbuf);
 	cblen -= F_INSN_SIZE(ipfw_insn_u32) + 1;
 
 #define	CHECK_RBUFLEN(len)	{ CHECK_LENGTH(rblen, len); rblen -= len; }