This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit acbb8b33f362cabdde0c5c7408f793d8a8002f51 Author: Junbo Zheng <[email protected]> AuthorDate: Sat Oct 3 23:37:35 2026 +0800 misc: Convert the remaining sizeof(arr)/sizeof(arr[0]) to nitems Convert the remaining open-coded sizeof(arr) / sizeof(arr[0]) occurrences to nitems() from <sys/param.h> across examples, industry, nshlib, system and the testing suites. Assisted-by: Claude Code (glm-5.3) <[email protected]> Signed-off-by: Junbo Zheng <[email protected]> --- examples/fmsynth/keyboard_main.c | 3 ++- examples/mml_parser/mml_parser_main.c | 3 ++- examples/sandbox/sandbox_main.c | 3 ++- industry/nxmodbus/core/nxmb_func.c | 3 ++- nshlib/nsh_identity.c | 3 ++- system/nxrecorder/nxrecorder.c | 3 ++- testing/crypto/passwd/pbkdf2_test.c | 3 ++- testing/libc/arch_libc/arch_libc_bench.c | 9 +++++---- testing/libc/crctest/crctest_main.c | 15 ++++++++------- testing/libc/stdbit/stdbit.c | 2 +- .../testsuites/kernel/socket/cases/net_socket_test_008.c | 3 ++- .../testsuites/kernel/socket/cases/net_socket_test_009.c | 3 ++- .../testsuites/kernel/socket/cases/net_socket_test_011.c | 3 ++- testing/testsuites/kernel/syscall/cases/fsync_test.c | 3 ++- .../testsuites/kernel/syscall/cases/getpeername_test.c | 3 ++- .../testsuites/kernel/syscall/cases/getsocketopt_test.c | 3 ++- testing/testsuites/kernel/syscall/cases/listen_test.c | 3 ++- testing/testsuites/kernel/syscall/cases/recvfrom_test.c | 3 ++- testing/testsuites/kernel/syscall/cases/sched_test.c | 3 ++- .../testsuites/kernel/syscall/cases/setsocketopt01_test.c | 3 ++- testing/testsuites/kernel/syscall/cases/socketpair_test.c | 5 +++-- testing/testsuites/kernel/time/cases/clock_test_timer03.c | 3 ++- 22 files changed, 53 insertions(+), 32 deletions(-) diff --git a/examples/fmsynth/keyboard_main.c b/examples/fmsynth/keyboard_main.c index e30eab3de..ddd7eaff3 100644 --- a/examples/fmsynth/keyboard_main.c +++ b/examples/fmsynth/keyboard_main.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> #include <stdio.h> +#include <sys/param.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> @@ -122,7 +123,7 @@ static struct key_convert_s key_convert[] = { OCTAVE(5, MUSIC_SCALE_E), ';', "O5E" }, }; -#define MAX_KEYCONVERT (sizeof(key_convert)/sizeof(key_convert[0])) +#define MAX_KEYCONVERT (nitems(key_convert)) /**************************************************************************** * Private functions diff --git a/examples/mml_parser/mml_parser_main.c b/examples/mml_parser/mml_parser_main.c index 4f4fe9bf2..7ccae800f 100644 --- a/examples/mml_parser/mml_parser_main.c +++ b/examples/mml_parser/mml_parser_main.c @@ -27,6 +27,7 @@ #include <nuttx/config.h> #include <stdio.h> +#include <sys/param.h> #ifndef CONFIG_AUDIOUTILS_MMLPARSER_LIB #error "This example needs to enable config of AUDIOUTILS_MMLPARSER_LIB," \ " please enable it" @@ -86,7 +87,7 @@ static const char *test_scores[] = SIMPLE_SCORE, TEST_SCORE, FLOH_WALZER_RIGHT, FLOH_WALZER_LEFT, }; -#define TEST_SCORES_NUM (sizeof(test_scores)/sizeof(test_scores[0])) +#define TEST_SCORES_NUM (nitems(test_scores)) /**************************************************************************** * Private Functions diff --git a/examples/sandbox/sandbox_main.c b/examples/sandbox/sandbox_main.c index e6b1188e8..df2cd6e2d 100644 --- a/examples/sandbox/sandbox_main.c +++ b/examples/sandbox/sandbox_main.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/wait.h> @@ -687,7 +688,7 @@ int main(int argc, FAR char *argv[]) { int n; - for (n = 0; n < (int)(sizeof(defaults) / sizeof(defaults[0])); n++) + for (n = 0; n < (int)(nitems(defaults)); n++) { if (resolve(defaults[n], &t) == OK) { diff --git a/industry/nxmodbus/core/nxmb_func.c b/industry/nxmodbus/core/nxmb_func.c index 13b595b4f..c41f37f03 100644 --- a/industry/nxmodbus/core/nxmb_func.c +++ b/industry/nxmodbus/core/nxmb_func.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <sys/param.h> #include <nuttx/compiler.h> #include <errno.h> @@ -103,7 +104,7 @@ static const struct nxmb_fc_entry_s g_nxmb_fc_table[] = }; #define NXMB_FC_TABLE_SIZE \ - (sizeof(g_nxmb_fc_table) / sizeof(g_nxmb_fc_table[0])) + (nitems(g_nxmb_fc_table)) /**************************************************************************** * Private Functions diff --git a/nshlib/nsh_identity.c b/nshlib/nsh_identity.c index 98204d408..2e0fb9798 100644 --- a/nshlib/nsh_identity.c +++ b/nshlib/nsh_identity.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <sys/param.h> #include <errno.h> #include <grp.h> #include <pwd.h> @@ -521,7 +522,7 @@ static void nsh_id_append_groups(FAR char *line, size_t linelen) int ngroups; int i; - ngroups = getgroups(sizeof(grouplist) / sizeof(grouplist[0]), grouplist); + ngroups = getgroups(nitems(grouplist), grouplist); if (ngroups <= 0) { return; diff --git a/system/nxrecorder/nxrecorder.c b/system/nxrecorder/nxrecorder.c index 2f6d01d22..dfc3c1961 100644 --- a/system/nxrecorder/nxrecorder.c +++ b/system/nxrecorder/nxrecorder.c @@ -39,6 +39,7 @@ #include <string.h> #include <strings.h> #include <sys/ioctl.h> +#include <sys/param.h> #include <sys/types.h> #include <unistd.h> @@ -1102,7 +1103,7 @@ int nxrecorder_recordinternal(FAR struct nxrecorder_s *precorder, goto err_out_nodev; } - for (index = 0; index < sizeof(g_enc_ops) / sizeof(g_enc_ops[0]); index++) + for (index = 0; index < nitems(g_enc_ops); index++) { if (g_enc_ops[index].format == filefmt) { diff --git a/testing/crypto/passwd/pbkdf2_test.c b/testing/crypto/passwd/pbkdf2_test.c index d1f0e718d..3e0e3af05 100644 --- a/testing/crypto/passwd/pbkdf2_test.c +++ b/testing/crypto/passwd/pbkdf2_test.c @@ -26,6 +26,7 @@ #include <nuttx/config.h> +#include <sys/param.h> #include <errno.h> #include <stdio.h> #include <string.h> @@ -159,7 +160,7 @@ static int test_pbkdf2_vectors(void) int i; int ret; - for (i = 0; i < (int)(sizeof(g_vectors) / sizeof(g_vectors[0])); i++) + for (i = 0; i < (int)(nitems(g_vectors)); i++) { vec = &g_vectors[i]; diff --git a/testing/libc/arch_libc/arch_libc_bench.c b/testing/libc/arch_libc/arch_libc_bench.c index c24118e1a..f19971c97 100644 --- a/testing/libc/arch_libc/arch_libc_bench.c +++ b/testing/libc/arch_libc/arch_libc_bench.c @@ -43,6 +43,7 @@ #include <nuttx/config.h> +#include <sys/param.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -167,9 +168,9 @@ static const uint8_t g_aligns[][2] = } }; -#define NOPS (sizeof(g_ops) / sizeof(g_ops[0])) -#define NSIZES (sizeof(g_sizes) / sizeof(g_sizes[0])) -#define NALIGNS (sizeof(g_aligns) / sizeof(g_aligns[0])) +#define NOPS (nitems(g_ops)) +#define NSIZES (nitems(g_sizes)) +#define NALIGNS (nitems(g_aligns)) /**************************************************************************** * Private Functions @@ -210,7 +211,7 @@ static bool bench_pick_clock(void) volatile int i; size_t k; - for (k = 0; k < sizeof(tries) / sizeof(tries[0]); k++) + for (k = 0; k < nitems(tries); k++) { if (clock_gettime(tries[k], &a) < 0) { diff --git a/testing/libc/crctest/crctest_main.c b/testing/libc/crctest/crctest_main.c index 6bc05ba94..995551f4c 100644 --- a/testing/libc/crctest/crctest_main.c +++ b/testing/libc/crctest/crctest_main.c @@ -24,6 +24,7 @@ #include <nuttx/config.h> #include <inttypes.h> +#include <sys/param.h> #include <setjmp.h> #include <stdbool.h> #include <stdint.h> @@ -249,7 +250,7 @@ static void test_case_crc8h1d(void **state) uint8_t crc8_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc8_value = crc8h1d(crc_test_data[index].data, @@ -275,7 +276,7 @@ static void test_case_crc8h2f(void **state) uint8_t crc8_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc8_value = crc8h2f(crc_test_data[index].data, @@ -301,7 +302,7 @@ static void test_case_crc16h1021(void **state) uint16_t crc16_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc16_value = crc16h1021(crc_test_data[index].data, @@ -327,7 +328,7 @@ static void test_case_crc16h8005(void **state) uint16_t crc16_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc16_value = crc16h8005(crc_test_data[index].data, @@ -353,7 +354,7 @@ static void test_case_crc32h04c11db7(void **state) uint32_t crc32_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc32_value = crc32h04c11db7(crc_test_data[index].data, @@ -379,7 +380,7 @@ static void test_case_crc32hf4acfb13(void **state) uint32_t crc32_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc32_value = crc32hf4acfb13(crc_test_data[index].data, @@ -405,7 +406,7 @@ static void test_case_crc64emac(void **state) uint64_t crc64_value; for (index = 0; - index < sizeof(crc_test_data) / sizeof(crc_test_data[0]); + index < nitems(crc_test_data); index++) { crc64_value = crc64emac(crc_test_data[index].data, diff --git a/testing/libc/stdbit/stdbit.c b/testing/libc/stdbit/stdbit.c index 9a5d485b5..298083775 100644 --- a/testing/libc/stdbit/stdbit.c +++ b/testing/libc/stdbit/stdbit.c @@ -1374,7 +1374,7 @@ int main(int argc, FAR char *argv[]) tests_ok = tests_err = 0; - for (i = 0; i < sizeof(g_entry_list) / sizeof(g_entry_list[0]); i++) + for (i = 0; i < nitems(g_entry_list); i++) { item = &g_entry_list[i]; ret = item->entry(); diff --git a/testing/testsuites/kernel/socket/cases/net_socket_test_008.c b/testing/testsuites/kernel/socket/cases/net_socket_test_008.c index a757a0c59..3ae7734de 100644 --- a/testing/testsuites/kernel/socket/cases/net_socket_test_008.c +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_008.c @@ -24,6 +24,7 @@ * Included Files ****************************************************************************/ #include <nuttx/config.h> +#include <sys/param.h> #include <sys/syscall.h> #include <unistd.h> #include <stdint.h> @@ -226,7 +227,7 @@ static void *clientsthread(void *param) "see u next time, ", "Bye!" }; - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) + for (int i = 0; i < nitems(msg); ++i) { if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { diff --git a/testing/testsuites/kernel/socket/cases/net_socket_test_009.c b/testing/testsuites/kernel/socket/cases/net_socket_test_009.c index b84705219..e4ca6e6d9 100644 --- a/testing/testsuites/kernel/socket/cases/net_socket_test_009.c +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_009.c @@ -24,6 +24,7 @@ * Included Files ****************************************************************************/ #include <nuttx/config.h> +#include <sys/param.h> #include <sys/syscall.h> #include <unistd.h> #include <stdint.h> @@ -228,7 +229,7 @@ static void *clientsthread(void *param) "see u next time, ", "Bye!" }; - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) + for (int i = 0; i < nitems(msg); ++i) { if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { diff --git a/testing/testsuites/kernel/socket/cases/net_socket_test_011.c b/testing/testsuites/kernel/socket/cases/net_socket_test_011.c index 90b13f8b0..191346bf1 100644 --- a/testing/testsuites/kernel/socket/cases/net_socket_test_011.c +++ b/testing/testsuites/kernel/socket/cases/net_socket_test_011.c @@ -24,6 +24,7 @@ * Included Files ****************************************************************************/ #include <nuttx/config.h> +#include <sys/param.h> #include <sys/syscall.h> #include <unistd.h> #include <stdint.h> @@ -194,7 +195,7 @@ static void *clientsthread(void *param) "Bye!", }; - for (int i = 0; i < sizeof(msg) / sizeof(msg[0]); ++i) + for (int i = 0; i < nitems(msg); ++i) { if (send(fd, msg[i], strlen(msg[i]), 0) < 0) { diff --git a/testing/testsuites/kernel/syscall/cases/fsync_test.c b/testing/testsuites/kernel/syscall/cases/fsync_test.c index d84f17937..2069f5688 100644 --- a/testing/testsuites/kernel/syscall/cases/fsync_test.c +++ b/testing/testsuites/kernel/syscall/cases/fsync_test.c @@ -28,6 +28,7 @@ #include <syslog.h> #include <unistd.h> #include <fcntl.h> +#include <sys/param.h> #include <sys/statvfs.h> #include <sys/resource.h> #include <time.h> @@ -150,7 +151,7 @@ void test_nuttx_syscall_fsync02(FAR void **state) close(pipe_fd[0]); - for (int i = 0; i < sizeof(tcases) / sizeof(tcases[0]); i++) + for (int i = 0; i < nitems(tcases); i++) { ret = fsync(*(tcases[i].fd)); if (ret != -1) diff --git a/testing/testsuites/kernel/syscall/cases/getpeername_test.c b/testing/testsuites/kernel/syscall/cases/getpeername_test.c index e5c82b6c1..e149ec129 100644 --- a/testing/testsuites/kernel/syscall/cases/getpeername_test.c +++ b/testing/testsuites/kernel/syscall/cases/getpeername_test.c @@ -31,6 +31,7 @@ #include <unistd.h> #include <fcntl.h> #include <syslog.h> +#include <sys/param.h> #include <sys/types.h> #include <errno.h> #include <sys/socket.h> @@ -124,7 +125,7 @@ test_cases[] = void test_nuttx_syscall_getpeername01(FAR void **state) { #ifdef CONFIG_NET_TCP - int total = sizeof(test_cases) / sizeof(test_cases[0]); + int total = nitems(test_cases); int ret; setup(); for (int i = 0; i < total; ++i) diff --git a/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c b/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c index 5f7898ffb..249563df8 100644 --- a/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c +++ b/testing/testsuites/kernel/syscall/cases/getsocketopt_test.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -139,7 +140,7 @@ void test_nuttx_syscall_getsockopt01(FAR void **state) int ret; int flag = 1; setup(); - for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + for (testno = 0; testno < nitems(tdat); ++testno) { tdat[testno].setup(); if (s < 0) diff --git a/testing/testsuites/kernel/syscall/cases/listen_test.c b/testing/testsuites/kernel/syscall/cases/listen_test.c index de016b009..b6021936e 100644 --- a/testing/testsuites/kernel/syscall/cases/listen_test.c +++ b/testing/testsuites/kernel/syscall/cases/listen_test.c @@ -29,6 +29,7 @@ #include <fcntl.h> #include <syslog.h> #include <stdio.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -90,7 +91,7 @@ void test_nuttx_syscall_listen01(FAR void **state) const char set[] = "setup0"; const char clean[] = "cleanup0"; - for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + for (testno = 0; testno < nitems(tdat); ++testno) { /* setup0(void) */ diff --git a/testing/testsuites/kernel/syscall/cases/recvfrom_test.c b/testing/testsuites/kernel/syscall/cases/recvfrom_test.c index b07d24a99..99de0b1a3 100644 --- a/testing/testsuites/kernel/syscall/cases/recvfrom_test.c +++ b/testing/testsuites/kernel/syscall/cases/recvfrom_test.c @@ -31,6 +31,7 @@ #include <errno.h> #include <fcntl.h> #include <syslog.h> +#include <sys/param.h> #include <sys/types.h> #include <stdint.h> #include <stdarg.h> @@ -409,7 +410,7 @@ void test_nuttx_syscall_recvfromtest01(FAR void **state) int flag = 1; setup(); - for (testno = 0; testno < sizeof(tdat) / sizeof(tdat[0]); ++testno) + for (testno = 0; testno < nitems(tdat); ++testno) { usleep(100000); if (tdat[testno].setup() < 0) diff --git a/testing/testsuites/kernel/syscall/cases/sched_test.c b/testing/testsuites/kernel/syscall/cases/sched_test.c index 901a34649..7f6c8ef04 100644 --- a/testing/testsuites/kernel/syscall/cases/sched_test.c +++ b/testing/testsuites/kernel/syscall/cases/sched_test.c @@ -27,6 +27,7 @@ #include <syslog.h> #include <dirent.h> #include <inttypes.h> +#include <sys/param.h> #include <sys/types.h> #include <stdlib.h> #include <unistd.h> @@ -177,7 +178,7 @@ void test_nuttx_syscall_sched04(FAR void **state) } }; - int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); + int TST_TOTAL = nitems(test_cases); #if CONFIG_RR_INTERVAL > 0 struct sched_param p = diff --git a/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c b/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c index adc991933..f499e41d4 100644 --- a/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c +++ b/testing/testsuites/kernel/syscall/cases/setsocketopt01_test.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -115,7 +116,7 @@ void test_nuttx_syscall_setsockopt01(FAR void **state) addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; - for (int n = 0; n < sizeof(testcase_list) / sizeof(testcase_list[0]); + for (int n = 0; n < nitems(testcase_list); n++) { int ret; diff --git a/testing/testsuites/kernel/syscall/cases/socketpair_test.c b/testing/testsuites/kernel/syscall/cases/socketpair_test.c index 60021d643..a7d968e3b 100644 --- a/testing/testsuites/kernel/syscall/cases/socketpair_test.c +++ b/testing/testsuites/kernel/syscall/cases/socketpair_test.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> @@ -110,7 +111,7 @@ void test_nuttx_syscall_socketpair01(FAR void **state) } }; - for (int n = 0; n < sizeof(tdat) / sizeof(tdat[0]); n++) + for (int n = 0; n < nitems(tdat); n++) { struct test_case_t *tc = &tdat[n]; ret = socketpair(tc->domain, tc->type, tc->proto, tc->sv); @@ -172,7 +173,7 @@ void test_nuttx_syscall_socketpair02(FAR void **state) } }; - for (int n = 0; n < sizeof(tcases) / sizeof(tcases[0]); n++) + for (int n = 0; n < nitems(tcases); n++) { int res; struct tcase *tc = &tcases[n]; diff --git a/testing/testsuites/kernel/time/cases/clock_test_timer03.c b/testing/testsuites/kernel/time/cases/clock_test_timer03.c index 76a42c760..c915e4076 100644 --- a/testing/testsuites/kernel/time/cases/clock_test_timer03.c +++ b/testing/testsuites/kernel/time/cases/clock_test_timer03.c @@ -25,6 +25,7 @@ ****************************************************************************/ #include <nuttx/config.h> #include <stdio.h> +#include <sys/param.h> #include <sys/stat.h> #include <dirent.h> #include <unistd.h> @@ -95,7 +96,7 @@ void test_nuttx_clock_test_timer03(FAR void **state) 0, 0 }; - for (int i = 0; i < sizeof(testcases) / sizeof(testcases[0]); ++i) + for (int i = 0; i < nitems(testcases); ++i) { struct timespec start; struct timespec end;
