Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Apr 2024 04:27:19 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 83409a9357a4 - main - moused: Use nitems(foo) instead of sizeof(foo)/sizeof(foo[0])
Message-ID:  <202404290427.43T4RJEe044772@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

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

commit 83409a9357a43f2ba595c84ae6904ab4c3ac1ab9
Author:     Elyes Haouas <ehaouas@noos.fr>
AuthorDate: 2023-11-07 17:12:44 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-29 03:30:54 +0000

    moused: 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>
---
 usr.sbin/moused/moused.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c
index 201e0b6ce0f6..068919f2e941 100644
--- a/usr.sbin/moused/moused.c
+++ b/usr.sbin/moused/moused.c
@@ -1033,7 +1033,7 @@ moused(void)
 	bstate[i].count = 0;
 	bstate[i].ts = mouse_button_state_ts;
     }
-    for (i = 0; i < (int)(sizeof(zstate) / sizeof(zstate[0])); ++i) {
+    for (i = 0; i < (int)nitems(zstate); ++i) {
 	zstate[i].count = 0;
 	zstate[i].ts = mouse_button_state_ts;
     }
@@ -1489,7 +1489,7 @@ r_identify(void)
     rodent.mode.level = 0;
     if (ioctl(rodent.mfd, MOUSE_GETMODE, &rodent.mode) == 0) {
 	if (rodent.mode.protocol == MOUSE_PROTO_UNKNOWN ||
-	    rodent.mode.protocol >= (int)(sizeof(proto) / sizeof(proto[0]))) {
+	    rodent.mode.protocol >= (int)nitems(proto)) {
 	    logwarnx("unknown mouse protocol (%d)", rodent.mode.protocol);
 	    return (MOUSE_PROTO_UNKNOWN);
 	} else {
@@ -1564,8 +1564,7 @@ r_name(int type)
 {
     const char *unknown = "unknown";
 
-    return (type == MOUSE_PROTO_UNKNOWN ||
-	type >= (int)(sizeof(rnames) / sizeof(rnames[0])) ?
+    return (type == MOUSE_PROTO_UNKNOWN || type >= (int)nitems(rnames) ?
 	unknown : rnames[type]);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404290427.43T4RJEe044772>