From 93e96d6c87dc8dd84cdfc56a155dc0611f55ac86 Mon Sep 17 00:00:00 2001 From: Elyes Haouas Date: Sun, 28 Apr 2024 20:55:30 -0600 Subject: [PATCH] rtadvd: 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 --- usr.sbin/rtadvd/control.c | 6 +++--- usr.sbin/rtadvd/control_server.c | 4 ++-- usr.sbin/rtadvd/if.c | 2 +- usr.sbin/rtadvd/rtadvd.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/usr.sbin/rtadvd/control.c b/usr.sbin/rtadvd/control.c index 80af6371a269..54a944833f64 100644 --- a/usr.sbin/rtadvd/control.c +++ b/usr.sbin/rtadvd/control.c @@ -27,8 +27,8 @@ * */ +#include #include -#include #include #include #include @@ -75,7 +75,7 @@ cm_recv(int fd, char *buf) pfds[0].events = POLLIN; for (;;) { - i = poll(pfds, sizeof(pfds)/sizeof(pfds[0]), + i = poll(pfds, nitems(pfds), CM_RECV_TIMEOUT); if (i == 0) @@ -131,7 +131,7 @@ cm_recv(int fd, char *buf) msglen); for (;;) { - i = poll(pfds, sizeof(pfds)/sizeof(pfds[0]), + i = poll(pfds, nitems(pfds), CM_RECV_TIMEOUT); if (i == 0) diff --git a/usr.sbin/rtadvd/control_server.c b/usr.sbin/rtadvd/control_server.c index e96a1958dd10..60fdc5ca2ec0 100644 --- a/usr.sbin/rtadvd/control_server.c +++ b/usr.sbin/rtadvd/control_server.c @@ -27,8 +27,8 @@ * */ +#include #include -#include #include #include #include @@ -527,7 +527,7 @@ cm_getprop(struct ctrl_msg_pl *cp) return (1); for (i = 0; - i < sizeof(getprop_dtable) / sizeof(getprop_dtable[0]); + i < nitems(getprop_dtable); i++) { if (strcmp(cp->cp_key, getprop_dtable[i].dt_comm) == 0) return (getprop_dtable[i].dt_act(cp)); diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c index 6212639ba028..e1702a0aa72a 100644 --- a/usr.sbin/rtadvd/if.c +++ b/usr.sbin/rtadvd/if.c @@ -642,7 +642,7 @@ getinet6sysctl(int code) mib[3] = code; size = sizeof(value); - if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, NULL, 0) + if (sysctl(mib, nitems(mib), &value, &size, NULL, 0) < 0) { syslog(LOG_ERR, "<%s>: failed to get ip6 sysctl(%d): %s", __func__, code, diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index aa9038b65e63..fa5640afa96c 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -328,7 +328,7 @@ main(int argc, char *argv[]) "<%s> there's no timer. waiting for inputs", __func__); } - if ((i = poll(set, sizeof(set)/sizeof(set[0]), + if ((i = poll(set, nitems(set), timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000) : INFTIM)) < 0) {