From 985ce548d2fe91172dc64159672fe1d60234e07e Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 16 Aug 2023 01:12:50 +0800 Subject: [PATCH 1/3] Change all sizeof(arr)/sizeof(arr[0]) to nitems Signed-off-by: Xiang Xiao --- builtin/builtin_list.c | 3 ++- canutils/libcanutils/lib.c | 15 ++++++--------- examples/adxl372_test/adxl372_test_main.c | 9 ++++----- examples/dac/dac_main.c | 11 ++++------- examples/ft80x/ft80x_main.c | 8 +++----- examples/ftpd/ftpd_main.c | 4 ++-- examples/lsm330spi_test/lsm330spi_test_main.c | 9 ++++----- examples/pdcurses/testcurs_main.c | 3 ++- examples/usrsocktest/usrsocktest_daemon.c | 17 +++++++---------- examples/usrsocktest/usrsocktest_main.c | 4 ---- examples/usrsocktest/usrsocktest_multi_thread.c | 15 ++++++--------- .../usrsocktest/usrsocktest_wake_with_signal.c | 4 ---- graphics/lvgl/port/lv_port_keypad.c | 3 ++- interpreters/bas/bas_statement.c | 3 ++- netutils/dhcp6c/dhcp6c.c | 7 +++---- netutils/iperf/iperf_main.c | 5 ++--- netutils/ntpclient/ntpclient.c | 7 ++----- netutils/thttpd/libhttpd.c | 5 +++-- netutils/thttpd/mime_types.h | 5 +++-- netutils/thttpd/tdate_parse.c | 10 ++++------ netutils/webserver/Kconfig | 8 ++++---- netutils/webserver/httpd.c | 3 ++- system/iptables/iptables.c | 2 +- system/nxplayer/nxplayer.c | 3 ++- system/nxplayer/nxplayer_mp3.c | 4 ++-- system/tcpdump/tcpdump.c | 2 +- system/ubloxmodem/ubloxmodem_main.c | 8 +++----- system/uorb/test/unit_test.c | 3 ++- testing/crypto/aescbc.c | 3 ++- testing/crypto/aesctr.c | 2 +- testing/crypto/aesxts.c | 4 ++-- testing/crypto/hash.c | 9 +++++---- testing/crypto/hmac.c | 7 ++++--- testing/drivertest/drivertest_framebuffer.c | 3 ++- testing/drivertest/drivertest_lcd.c | 3 ++- testing/scanftest/scanftest_main.c | 7 +++---- testing/sensortest/sensortest.c | 4 ++-- wireless/ieee802154/i8sak/i8sak_main.c | 5 ++--- wireless/iwpan/src/iwpan.c | 5 ++--- wireless/wapi/src/wapi.c | 5 ++--- 40 files changed, 107 insertions(+), 130 deletions(-) diff --git a/builtin/builtin_list.c b/builtin/builtin_list.c index f8fe389b16..dcc10e10b6 100644 --- a/builtin/builtin_list.c +++ b/builtin/builtin_list.c @@ -25,6 +25,7 @@ #include #include +#include #include @@ -52,7 +53,7 @@ const struct builtin_s g_builtins[] = #endif }; -const int g_builtin_count = sizeof(g_builtins) / sizeof(g_builtins[0]); +const int g_builtin_count = nitems(g_builtins); /**************************************************************************** * Private Data diff --git a/canutils/libcanutils/lib.c b/canutils/libcanutils/lib.c index f12cfc3f76..f84974a81d 100644 --- a/canutils/libcanutils/lib.c +++ b/canutils/libcanutils/lib.c @@ -46,6 +46,7 @@ #include #include +#include #include /* for sa_family_t */ #include #include @@ -496,10 +497,6 @@ static const char *protocol_violation_locations[] = { "unspecified", }; -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif - static int snprintf_error_data(char *buf, size_t len, uint8_t err, const char **arr, int arr_len) { @@ -537,7 +534,7 @@ static int snprintf_error_ctrl(char *buf, size_t len, const struct canfd_frame * n += snprintf(buf + n, len - n, "{"); n += snprintf_error_data(buf + n, len - n, cf->data[1], controller_problems, - ARRAY_SIZE(controller_problems)); + nitems(controller_problems)); n += snprintf(buf + n, len - n, "}"); return n; @@ -553,10 +550,10 @@ static int snprintf_error_prot(char *buf, size_t len, const struct canfd_frame * n += snprintf(buf + n, len - n, "{{"); n += snprintf_error_data(buf + n, len - n, cf->data[2], protocol_violation_types, - ARRAY_SIZE(protocol_violation_types)); + nitems(protocol_violation_types)); n += snprintf(buf + n, len - n, "}{"); if (cf->data[3] > 0 && - cf->data[3] < ARRAY_SIZE(protocol_violation_locations)) + cf->data[3] < nitems(protocol_violation_locations)) n += snprintf(buf + n, len - n, "%s", protocol_violation_locations[cf->data[3]]); n += snprintf(buf + n, len - n, "}}"); @@ -575,7 +572,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c return; class = cf->can_id & CAN_EFF_MASK; - if (class > (1 << ARRAY_SIZE(error_classes))) { + if (class > (1 << nitems(error_classes))) { fprintf(stderr, "Error class %#jx is invalid\n", (uintmax_t)class); return; } @@ -583,7 +580,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c if (!sep) sep = defsep; - for (i = 0; i < (int)ARRAY_SIZE(error_classes); i++) { + for (i = 0; i < (int)nitems(error_classes); i++) { mask = 1 << i; if (class & mask) { if (classes) diff --git a/examples/adxl372_test/adxl372_test_main.c b/examples/adxl372_test/adxl372_test_main.c index e301559457..2c05d61ba0 100644 --- a/examples/adxl372_test/adxl372_test_main.c +++ b/examples/adxl372_test/adxl372_test_main.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,7 +41,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0])) #define PASSED 0 #define SUB_PROMPT "stst >" @@ -394,7 +393,7 @@ int main(int argc, FAR char *argv[]) adxl372_test, /* ADXL372 accelerometer tests */ }; - FAR char *test_path[ARRAYSIZE(test_ptr_array)]; + FAR char *test_path[nitems(test_ptr_array)]; if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0) { @@ -490,7 +489,7 @@ int main(int argc, FAR char *argv[]) printf("Set to batch mode.\n"); } } - else if (ui >= ARRAYSIZE(test_ptr_array)) + else if (ui >= nitems(test_ptr_array)) { printf("Huh?\n"); } @@ -511,7 +510,7 @@ int main(int argc, FAR char *argv[]) { printf("ADXL372 sensor diagnostic started in batch mode...\n"); - for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++) + for (ui = 0; ui < nitems(test_ptr_array); ui++) { step_rc = 0; if (test_ptr_array[ui] != 0) diff --git a/examples/dac/dac_main.c b/examples/dac/dac_main.c index c4f335b29e..d9dda7010c 100644 --- a/examples/dac/dac_main.c +++ b/examples/dac/dac_main.c @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -47,10 +48,6 @@ # define CONFIG_EXAMPLES_DAC_DEVPATH "/dev/dac0" #endif -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -226,7 +223,7 @@ static int cmd_dac_put(int argc, FAR const char *argv[]) { msgs[0].am_channel = g_dacstate.channel; msgs[0].am_data = data; - ret = dac_put(g_dacstate.devpath, msgs, ARRAY_SIZE(msgs), delay); + ret = dac_put(g_dacstate.devpath, msgs, nitems(msgs), delay); printf("ret=%d\n", ret); } @@ -277,7 +274,7 @@ static void dac_help(void) "Default: %s Current: %s\n", CONFIG_EXAMPLES_DAC_DEVPATH, g_dacstate.devpath ? g_dacstate.devpath : "NONE"); - print_cmds("\nCommands:\n", commands, ARRAY_SIZE(commands), "\n"); + print_cmds("\nCommands:\n", commands, nitems(commands), "\n"); } static int arg_string(FAR const char **arg, FAR const char **value) @@ -422,7 +419,7 @@ int main(int argc, FAR const char *argv[]) } else { - ret = execute_cmd(argc, argv, commands, ARRAY_SIZE(commands)); + ret = execute_cmd(argc, argv, commands, nitems(commands)); } return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/examples/ft80x/ft80x_main.c b/examples/ft80x/ft80x_main.c index da79bf92aa..c889197472 100644 --- a/examples/ft80x/ft80x_main.c +++ b/examples/ft80x/ft80x_main.c @@ -30,6 +30,7 @@ #include #include +#include #include #include "graphics/ft80x.h" @@ -88,7 +89,6 @@ static const struct ft80x_exampleinfo_s g_primitives[] = { "Alpha Blend", ft80x_prim_alphablend } }; -#define NPRIMITIVES (sizeof(g_primitives) / sizeof(struct ft80x_exampleinfo_s)) #endif /* CONFIG_EXAMPLES_FT80X_PRIMITIVES */ /* Co-processor display examples. Only a small, but interesting, subset @@ -139,8 +139,6 @@ static const struct ft80x_exampleinfo_s g_coproc[] = { "Logo", ft80x_coproc_logo } }; -#define NCOPROC (sizeof(g_coproc) / sizeof(struct ft80x_exampleinfo_s)) - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -308,7 +306,7 @@ int main(int argc, FAR char *argv[]) ft80x_info("FT80x Primitive Functions\n"); - for (i = 0; i < NPRIMITIVES; i++) + for (i = 0; i < nitems(g_primitives); i++) { ft80x_example(fd, buffer, &g_primitives[i]); } @@ -318,7 +316,7 @@ int main(int argc, FAR char *argv[]) ft80x_info("FT80x Co-processor Functions\n"); - for (i = 0; i < NCOPROC; i++) + for (i = 0; i < nitems(g_coproc); i++) { ft80x_example(fd, buffer, &g_coproc[i]); } diff --git a/examples/ftpd/ftpd_main.c b/examples/ftpd/ftpd_main.c index e0eda11b40..d1052b50c3 100644 --- a/examples/ftpd/ftpd_main.c +++ b/examples/ftpd/ftpd_main.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -65,7 +66,6 @@ static const struct fptd_account_s g_ftpdaccounts[] = { FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL }, { FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL }, }; -#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s)) /**************************************************************************** * Public Data @@ -139,7 +139,7 @@ static void ftpd_accounts(FTPD_SESSION handle) int i; printf("Adding accounts:\n"); - for (i = 0; i < NACCOUNTS; i++) + for (i = 0; i < nitems(g_ftpdaccounts); i++) { account = &g_ftpdaccounts[i]; diff --git a/examples/lsm330spi_test/lsm330spi_test_main.c b/examples/lsm330spi_test/lsm330spi_test_main.c index ca1a5361d6..f78032a6f9 100644 --- a/examples/lsm330spi_test/lsm330spi_test_main.c +++ b/examples/lsm330spi_test/lsm330spi_test_main.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -41,7 +41,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0])) #define PASSED 0 #define SUB_PROMPT "stst >" @@ -631,7 +630,7 @@ int main(int argc, FAR char *argv[]) lsm330gyro_test, /* LSM330 gyroscope tests */ }; - FAR char *test_path[ARRAYSIZE(test_ptr_array)]; + FAR char *test_path[nitems(test_ptr_array)]; if (argc < 2 || *argv[1] == 0 || *(argv[1] + 1) == 0) { @@ -737,7 +736,7 @@ int main(int argc, FAR char *argv[]) printf("Set to batch mode.\n"); } } - else if (ui >= ARRAYSIZE(test_ptr_array)) + else if (ui >= nitems(test_ptr_array)) { printf("Huh?\n"); } @@ -757,7 +756,7 @@ int main(int argc, FAR char *argv[]) else /* not interactive mode */ { printf("LSM330 sensor diagnostic started in batch mode...\n"); - for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++) + for (ui = 0; ui < nitems(test_ptr_array); ui++) { step_rc = 0; if (test_ptr_array[ui] != 0) diff --git a/examples/pdcurses/testcurs_main.c b/examples/pdcurses/testcurs_main.c index 14ac2ed889..14d2951d2f 100644 --- a/examples/pdcurses/testcurs_main.c +++ b/examples/pdcurses/testcurs_main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "graphics/curses.h" @@ -123,7 +124,7 @@ static const COMMAND command[] = #endif }; -#define MAX_OPTIONS (sizeof(command) / sizeof(COMMAND)) +#define MAX_OPTIONS nitems(command) static int height; static int width; diff --git a/examples/usrsocktest/usrsocktest_daemon.c b/examples/usrsocktest/usrsocktest_daemon.c index e2b15888ba..37303fec11 100644 --- a/examples/usrsocktest/usrsocktest_daemon.c +++ b/examples/usrsocktest/usrsocktest_daemon.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -58,10 +59,6 @@ #define TEST_SOCKET_SOCKID_BASE 10000U #define TEST_SOCKET_COUNT 8 -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - #define noinline /**************************************************************************** @@ -140,7 +137,7 @@ static int test_socket_alloc(FAR struct daemon_priv_s *priv) { int i; - for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) + for (i = 0; i < nitems(priv->test_sockets); i++) { FAR struct test_socket_s *tsock = &priv->test_sockets[i]; @@ -172,7 +169,7 @@ static FAR struct test_socket_s *test_socket_get( } sockid -= TEST_SOCKET_SOCKID_BASE; - if (sockid >= ARRAY_SIZE(priv->test_sockets)) + if (sockid >= nitems(priv->test_sockets)) { return NULL; } @@ -245,13 +242,13 @@ static int tsock_send_event(int fd, FAR struct daemon_priv_s *priv, event.head.flags = USRSOCK_MESSAGE_FLAG_EVENT; event.head.msgid = USRSOCK_MESSAGE_SOCKET_EVENT; - for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) + for (i = 0; i < nitems(priv->test_sockets); i++) { if (tsock == &priv->test_sockets[i]) break; } - if (i == ARRAY_SIZE(priv->test_sockets)) + if (i == nitems(priv->test_sockets)) { return -EINVAL; } @@ -1777,7 +1774,7 @@ static int for_each_connection(int fd, FAR struct daemon_priv_s *priv, { int i; - for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) + for (i = 0; i < nitems(priv->test_sockets); i++) { FAR struct test_socket_s *tsock = &priv->test_sockets[i]; @@ -2114,7 +2111,7 @@ int usrsocktest_daemon_stop(void) goto out; } - for (i = 0; i < ARRAY_SIZE(priv->test_sockets); i++) + for (i = 0; i < nitems(priv->test_sockets); i++) { if (priv->test_sockets[i].opened && priv->test_sockets[i].endp != NULL) { diff --git a/examples/usrsocktest/usrsocktest_main.c b/examples/usrsocktest/usrsocktest_main.c index 2d854d87a2..9545eac073 100644 --- a/examples/usrsocktest/usrsocktest_main.c +++ b/examples/usrsocktest/usrsocktest_main.c @@ -54,10 +54,6 @@ #define usrsocktest_dbg(...) ((void)0) -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/examples/usrsocktest/usrsocktest_multi_thread.c b/examples/usrsocktest/usrsocktest_multi_thread.c index e9f56fbd3d..a233f3e340 100644 --- a/examples/usrsocktest/usrsocktest_multi_thread.c +++ b/examples/usrsocktest/usrsocktest_multi_thread.c @@ -22,6 +22,7 @@ * Included Files ****************************************************************************/ +#include #include #include #include @@ -34,10 +35,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -115,12 +112,12 @@ TEST_SETUP(multithread) { int i; - for (i = 0; i < ARRAY_SIZE(sds); i++) + for (i = 0; i < nitems(sds); i++) { sds[i] = -1; } - for (i = 0; i < ARRAY_SIZE(tids); i++) + for (i = 0; i < nitems(tids); i++) { tids[i] = -1; } @@ -150,7 +147,7 @@ TEST_TEAR_DOWN(multithread) int ret; int i; - for (i = 0; i < ARRAY_SIZE(tids); i++) + for (i = 0; i < nitems(tids); i++) { if (tids[i] != -1) { @@ -161,7 +158,7 @@ TEST_TEAR_DOWN(multithread) } } - for (i = 0; i < ARRAY_SIZE(sds); i++) + for (i = 0; i < nitems(sds); i++) { if (sds[i] != -1) { @@ -213,7 +210,7 @@ TEST(multithread, open_close) /* Launch worker threads. */ - for (i = 0; i < ARRAY_SIZE(tids); i++) + for (i = 0; i < nitems(tids); i++) { ret = pthread_create(&tids[i], NULL, usrsock_socket_multitask_thread, sds + i); diff --git a/examples/usrsocktest/usrsocktest_wake_with_signal.c b/examples/usrsocktest/usrsocktest_wake_with_signal.c index 8cf0af4432..ceb84fca5f 100644 --- a/examples/usrsocktest/usrsocktest_wake_with_signal.c +++ b/examples/usrsocktest/usrsocktest_wake_with_signal.c @@ -38,10 +38,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - #define TEST_FLAG_PAUSE_USRSOCK_HANDLING (1 << 0) #define TEST_FLAG_DAEMON_ABORT (1 << 1) #define TEST_FLAG_MULTI_THREAD (1 << 2) diff --git a/graphics/lvgl/port/lv_port_keypad.c b/graphics/lvgl/port/lv_port_keypad.c index f45099ca5e..e80f6d7743 100644 --- a/graphics/lvgl/port/lv_port_keypad.c +++ b/graphics/lvgl/port/lv_port_keypad.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -114,7 +115,7 @@ static uint32_t keypad_get_key(int fd) return 0; } - for (i = 0; i < sizeof(g_keypad_map) / sizeof(struct keypad_map_s); i++) + for (i = 0; i < nitems(g_keypad_map); i++) { int bit = g_keypad_map[i].bit; diff --git a/interpreters/bas/bas_statement.c b/interpreters/bas/bas_statement.c index 1941236779..482f94f62a 100644 --- a/interpreters/bas/bas_statement.c +++ b/interpreters/bas/bas_statement.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "bas_statement.h" @@ -1181,7 +1182,7 @@ struct Value *stmt_EDIT(struct Value *value) String_new(&cmd); String_appendChars(&cmd, visual); String_appendChar(&cmd, ' '); - for (i = 0; i < sizeof(gotoLine) / sizeof(gotoLine[0]); ++i) + for (i = 0; i < nitems(gotoLine); ++i) { if (strcmp(basename, gotoLine[i].editor) == 0) { diff --git a/netutils/dhcp6c/dhcp6c.c b/netutils/dhcp6c/dhcp6c.c index 8fc9f82106..678ce4db59 100644 --- a/netutils/dhcp6c/dhcp6c.c +++ b/netutils/dhcp6c/dhcp6c.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -40,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -63,8 +64,6 @@ #define DHCPV6_DUID_LLADDR 3 #define DHCPV6_REQ_DELAY 1 -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - #define dhcpv6_for_each_option(_o, start, end, otype, olen, odata)\ for ((_o) = (FAR uint8_t *)(start); (_o) + 4 <= (FAR uint8_t *)(end) &&\ ((otype) = (_o)[0] << 8 | (_o)[1]) && ((odata) = (FAR void *)&(_o)[4]) &&\ @@ -614,7 +613,7 @@ static void dhcp6c_send(FAR void *handle, enum dhcpv6_msg_e type, dhcp6c_set_iov(&iov[9], &hdr_ia_pd, sizeof(hdr_ia_pd)); dhcp6c_set_iov(&iov[10], ia_pd, ia_pd_len); - cnt = ARRAY_SIZE(iov); + cnt = nitems(iov); if (type == DHCPV6_MSG_INFO_REQ) { cnt = 5; diff --git a/netutils/iperf/iperf_main.c b/netutils/iperf/iperf_main.c index a513590917..46abf8bbb0 100644 --- a/netutils/iperf/iperf_main.c +++ b/netutils/iperf/iperf_main.c @@ -85,7 +85,7 @@ static void iperf_showusage(FAR const char *progname, printf("iperf command:\n"); arg_print_glossary(stdout, (FAR void **)args, NULL); - arg_freetable((FAR void **)args, sizeof(*args) / sizeof(FAR void *)); + arg_freetable((FAR void **)args, 1); exit(exitcode); } @@ -301,8 +301,7 @@ int main(int argc, FAR char *argv[]) iperf_start(&cfg); out: - arg_freetable((FAR void **)&iperf_args, - sizeof(iperf_args) / sizeof(FAR void *)); + arg_freetable((FAR void **)&iperf_args, 1); return 0; } diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c index 7374c00a2c..8ec85d22e6 100644 --- a/netutils/ntpclient/ntpclient.c +++ b/netutils/ntpclient/ntpclient.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -100,10 +101,6 @@ #define MAX_SERVER_SELECTION_RETRIES 3 -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - #ifndef STR # define STR2(x) #x # define STR(x) STR2(x) @@ -1003,7 +1000,7 @@ static int ntp_get_next_hostip(FAR struct ntp_servers_s *srvs, /* Refresh DNS for new IP-addresses. */ ret = ntp_gethostip_multi(hostname, srvs->list, - ARRAY_SIZE(srvs->list)); + nitems(srvs->list)); if (ret <= 0) { return ERROR; diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c index bdc747caff..9c07f93e7d 100644 --- a/netutils/thttpd/libhttpd.c +++ b/netutils/thttpd/libhttpd.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -1503,7 +1504,7 @@ static void figure_mime(httpd_conn *hc) if (ext_len == enc_tab[i].ext_len && strncasecmp(ext, enc_tab[i].ext, ext_len) == 0) { - if (n_me_indexes < sizeof(me_indexes) / sizeof(*me_indexes)) + if (n_me_indexes < nitems(me_indexes)) { me_indexes[n_me_indexes] = i; ++n_me_indexes; @@ -3284,7 +3285,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp) /* Check for an index file. */ - for (i = 0; i < sizeof(index_names) / sizeof(char *); ++i) + for (i = 0; i < nitems(index_names); ++i) { httpd_realloc_str(&indexname, &maxindexname, expnlen + 1 + strlen(index_names[i])); diff --git a/netutils/thttpd/mime_types.h b/netutils/thttpd/mime_types.h index 5c14a74b8a..6b6b290054 100644 --- a/netutils/thttpd/mime_types.h +++ b/netutils/thttpd/mime_types.h @@ -45,6 +45,7 @@ ****************************************************************************/ #include +#include /**************************************************************************** * Private Types @@ -73,7 +74,7 @@ static struct mime_entry enc_tab[] = { "gz", 0, "gzip", 0 }, { "uu", 0, "x-uuencode", 0 }, }; -static const int n_enc_tab = sizeof(enc_tab) / sizeof(*enc_tab); +static const int n_enc_tab = nitems(enc_tab); /* A list of file extensions followed by the corresponding MIME type. * Extensions not found in the table are returned as text/plain. @@ -273,6 +274,6 @@ static struct mime_entry typ_tab[] = { "xyz", 0, "chemical/x-xyz", 0 }, { "zip", 0, "application/zip", 0 }, }; -static const int n_typ_tab = sizeof(typ_tab) / sizeof(*typ_tab); +static const int n_typ_tab = nitems(typ_tab); #endif /* __APPS_NETUTILS_THTTPD_MIME_TYPES_H */ diff --git a/netutils/thttpd/tdate_parse.c b/netutils/thttpd/tdate_parse.c index de3f8851d3..995af3a950 100644 --- a/netutils/thttpd/tdate_parse.c +++ b/netutils/thttpd/tdate_parse.c @@ -143,14 +143,13 @@ static int scan_wday(char *str_wday, long *tm_wdayP) if (!sorted) { - qsort(wday_tab, sizeof(wday_tab) / sizeof(struct strlong), + qsort(wday_tab, nitems(wday_tab), sizeof(struct strlong), strlong_compare); sorted = 1; } pound_case(str_wday); - return strlong_search(str_wday, wday_tab, - sizeof(wday_tab) / sizeof(struct strlong), tm_wdayP); + return strlong_search(str_wday, wday_tab, nitems(wday_tab), tm_wdayP); } #endif /* Day of week not yet supported by NuttX */ @@ -176,14 +175,13 @@ static int scan_mon(char *str_mon, long *tm_monP) if (!sorted) { - qsort(mon_tab, sizeof(mon_tab) / sizeof(struct strlong), + qsort(mon_tab, nitems(mon_tab), sizeof(struct strlong), strlong_compare); sorted = 1; } pound_case(str_mon); - return strlong_search(str_mon, mon_tab, - sizeof(mon_tab) / sizeof(struct strlong), tm_monP); + return strlong_search(str_mon, mon_tab, nitems(mon_tab), tm_monP); } #endif diff --git a/netutils/webserver/Kconfig b/netutils/webserver/Kconfig index 1140f0c56b..6f33542e64 100644 --- a/netutils/webserver/Kconfig +++ b/netutils/webserver/Kconfig @@ -57,12 +57,12 @@ config NETUTILS_HTTPD_CGIPATH used thus: const static struct httpd_cgi_call a[] = { - { NULL, "/abc", cgi_abc }, - { NULL, "/xyz", cgi_xyz } + { NULL, "/abc", cgi_abc }, + { NULL, "/xyz", cgi_xyz } }; - for (i = 0; i < sizeof a / sizeof *a; i++) { - httpd_cgi_register(&a[i]); + for (i = 0; i < nitems(a); i++) { + httpd_cgi_register(&a[i]); } Where (under NETUTILS_HTTPD_CGIPATH) the "/xyz" is a URL path, diff --git a/netutils/webserver/httpd.c b/netutils/webserver/httpd.c index 14aa2a33f9..4602e65e9a 100644 --- a/netutils/webserver/httpd.c +++ b/netutils/webserver/httpd.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -988,7 +989,7 @@ int httpd_send_headers(struct httpd_state *pstate, int status, int len) { mime = "text/plain"; - for (i = 0; i < sizeof a / sizeof *a; i++) + for (i = 0; i < nitems(a); i++) { if (strncmp(a[i].ext, ptr + 1, strlen(a[i].ext)) == 0) { diff --git a/system/iptables/iptables.c b/system/iptables/iptables.c index 8cbc958acc..3021619bbb 100644 --- a/system/iptables/iptables.c +++ b/system/iptables/iptables.c @@ -455,6 +455,6 @@ int main(int argc, FAR char *argv[]) printf("Unknown table: %s\n", args.table->sval[0]); } - arg_freetable((FAR void **)&args, sizeof(args) / sizeof(FAR void *)); + arg_freetable((FAR void **)&args, 1); return ret; } diff --git a/system/nxplayer/nxplayer.c b/system/nxplayer/nxplayer.c index 6260009820..a0d10e5907 100644 --- a/system/nxplayer/nxplayer.c +++ b/system/nxplayer/nxplayer.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #ifdef CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT # include @@ -1900,7 +1901,7 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer, goto err_out_nodev; } - for (c = 0; c < sizeof(g_dec_ops) / sizeof(g_dec_ops[0]); c++) + for (c = 0; c < nitems(g_dec_ops); c++) { if (g_dec_ops[c].format == filefmt) { diff --git a/system/nxplayer/nxplayer_mp3.c b/system/nxplayer/nxplayer_mp3.c index 7f62241a5b..445fe29dda 100644 --- a/system/nxplayer/nxplayer_mp3.c +++ b/system/nxplayer/nxplayer_mp3.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -157,8 +158,7 @@ static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate, padding = (header >> 9) & 1; mode = (header >> 6) & 3; - if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) || - br_idx >= 0xf) + if (sr_idx >= nitems(g_mpa_freq_tab) || br_idx >= 0xf) { return -EINVAL; } diff --git a/system/tcpdump/tcpdump.c b/system/tcpdump/tcpdump.c index 2a43cfc364..c1988d4012 100644 --- a/system/tcpdump/tcpdump.c +++ b/system/tcpdump/tcpdump.c @@ -312,6 +312,6 @@ int main(int argc, FAR char *argv[]) close(cfgs.fd); out: - arg_freetable((FAR void **)&args, sizeof(args) / sizeof(FAR void *)); + arg_freetable((FAR void **)&args, 1); return 0; } diff --git a/system/ubloxmodem/ubloxmodem_main.c b/system/ubloxmodem/ubloxmodem_main.c index 2f49f92541..76f827f62a 100644 --- a/system/ubloxmodem/ubloxmodem_main.c +++ b/system/ubloxmodem/ubloxmodem_main.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -247,9 +248,7 @@ static int ubloxmodem_help(FAR struct ubloxmodem_cxt *cxt) printf("Usage: ubloxmodem [arguments]\n" " where is one of\n"); - for (i = 0; - i < sizeof(cmdmap) / sizeof(struct cmdinfo); - i++) + for (i = 0; i < nitems(cmdmap); i++) { printf("%s\n %s\n %s\n", cmdmap[i].name, @@ -375,8 +374,7 @@ static int ubloxmodem_parse(FAR struct ubloxmodem_cxt *cxt) { int i; - for (i = 0; - i < sizeof(cmdmap) / sizeof(struct cmdinfo) && + for (i = 0; i < nitems(cmdmap) && cxt->cmd == UBLOXMODEM_CMD_UNKNOWN; i++) { diff --git a/system/uorb/test/unit_test.c b/system/uorb/test/unit_test.c index 902acde3d6..471b471c38 100644 --- a/system/uorb/test/unit_test.c +++ b/system/uorb/test/unit_test.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "utility.h" @@ -89,7 +90,7 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[]) /* wait for up to 500ms for data */ - pret = poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 500); + pret = poll(&fds[0], nitems(fds), 500); if (fds[0].revents & POLLIN) { unsigned elt; diff --git a/testing/crypto/aescbc.c b/testing/crypto/aescbc.c index e21d23548e..638f4f411f 100644 --- a/testing/crypto/aescbc.c +++ b/testing/crypto/aescbc.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -192,7 +193,7 @@ int main(int argc, char *argv[]) int ret; unsigned char out[64]; - for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++) + for (int i = 0; i < nitems(testcase); i++) { ret = syscrypt(testcase[i].key, 16, testcase[i].iv, testcase[i].plain, out, testcase[i].len, 1); diff --git a/testing/crypto/aesctr.c b/testing/crypto/aesctr.c index ee6e13c979..852b179ebb 100644 --- a/testing/crypto/aesctr.c +++ b/testing/crypto/aesctr.c @@ -351,7 +351,7 @@ int main(int argc, FAR char **argv) int fail = 0; int i; - for (i = 0; i < (sizeof(tests) / sizeof(tests[0])); i++) + for (i = 0; i < nitems(tests); i++) { fail += run(i); } diff --git a/testing/crypto/aesxts.c b/testing/crypto/aesxts.c index b99698db3b..dce7a9166e 100644 --- a/testing/crypto/aesxts.c +++ b/testing/crypto/aesxts.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -1727,7 +1728,6 @@ struct aes_xts_tv aes_xts_test_vectors[] = }, }, }; -#define N_VECTORS (sizeof(aes_xts_test_vectors) / sizeof(*aes_xts_test_vectors)) static int match(FAR unsigned char *a, FAR unsigned char *b, size_t len) { @@ -1837,7 +1837,7 @@ int main(int argc, FAR char **argv) int fail = 0; size_t i; - for (i = 0; i < N_VECTORS; i++) + for (i = 0; i < nitems(aes_xts_test_vectors); i++) { tv = &aes_xts_test_vectors[i]; diff --git a/testing/crypto/hash.c b/testing/crypto/hash.c index 260e2e80bb..6ab7a697c9 100644 --- a/testing/crypto/hash.c +++ b/testing/crypto/hash.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -326,7 +327,7 @@ int main(void) printf("syshash init failed\n"); } - for (i = 0; i < sizeof(md5_testcase) / sizeof(tb); i++) + for (i = 0; i < nitems(md5_testcase); i++) { ret = syshash_start(&md5_ctx, CRYPTO_MD5); if (ret != 0) @@ -362,7 +363,7 @@ int main(void) } } - for (i = 0; i < sizeof(sha_testcase) / sizeof(struct tb); i++) + for (i = 0; i < nitems(sha_testcase); i++) { ret = syshash_start(&sha1_ctx, CRYPTO_SHA1); if (ret != 0) @@ -417,7 +418,7 @@ int main(void) } } - for (i = 0; i < sizeof(sha_testcase) / sizeof(struct tb); i++) + for (i = 0; i < nitems(sha_testcase); i++) { ret = syshash_start(&sha2_256_ctx, CRYPTO_SHA2_256); if (ret != 0) @@ -470,7 +471,7 @@ int main(void) } } - for (i = 0; i < sizeof(sha512_testcase) / sizeof(struct tb); i++) + for (i = 0; i < nitems(sha512_testcase); i++) { ret = syshash_start(&sha2_512_ctx, CRYPTO_SHA2_512); if (ret != 0) diff --git a/testing/crypto/hmac.c b/testing/crypto/hmac.c index fda24dd277..cbad8decb1 100644 --- a/testing/crypto/hmac.c +++ b/testing/crypto/hmac.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -192,7 +193,7 @@ int main(void) { char output[32]; int ret = 0; - for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++) + for (int i = 0; i < nitems(testcase) i++) { ret += syshmac(CRYPTO_MD5_HMAC, testcase[i].key, testcase[i].keylen, @@ -215,7 +216,7 @@ int main(void) } } - for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++) + for (int i = 0; i < nitems(testcase); i++) { ret = syshmac(CRYPTO_SHA1_HMAC, testcase[i].key, testcase[i].keylen, @@ -238,7 +239,7 @@ int main(void) } } - for (int i = 0; i < sizeof(testcase) / sizeof(struct tb); i++) + for (int i = 0; i < nitems(testcase); i++) { ret = syshmac(CRYPTO_SHA2_256_HMAC, testcase[i].key, testcase[i].keylen, diff --git a/testing/drivertest/drivertest_framebuffer.c b/testing/drivertest/drivertest_framebuffer.c index 5302c59193..a0566cea82 100644 --- a/testing/drivertest/drivertest_framebuffer.c +++ b/testing/drivertest/drivertest_framebuffer.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -283,7 +284,7 @@ static void test_case_fb_2(FAR void **state) const uint32_t xres = fb_state->fb_info.video_info.xres; const uint32_t yres = fb_state->fb_info.video_info.yres; - step_num = sizeof(colors_to_show) / sizeof(uint32_t); + step_num = nitems(colors_to_show); step_width = xres / step_num; for (i = 0; i < step_num; i++) { diff --git a/testing/drivertest/drivertest_lcd.c b/testing/drivertest/drivertest_lcd.c index 2e0a2f6873..e9ca3713f8 100644 --- a/testing/drivertest/drivertest_lcd.c +++ b/testing/drivertest/drivertest_lcd.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -342,7 +343,7 @@ static void test_case_lcd_2(FAR void **state) const uint32_t xres = lcd_state->lcd_info.video_info.xres; const uint32_t yres = lcd_state->lcd_info.video_info.yres; - step_num = sizeof(colors_to_show) / sizeof(uint32_t); + step_num = nitems(colors_to_show); step_width = xres / step_num; for (i = 0; i < step_num; i++) { diff --git a/testing/scanftest/scanftest_main.c b/testing/scanftest/scanftest_main.c index df1d7791b7..b51bea89d8 100644 --- a/testing/scanftest/scanftest_main.c +++ b/testing/scanftest/scanftest_main.c @@ -61,6 +61,7 @@ #include #include +#include #include #include @@ -78,8 +79,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define ARRAYSIZE(a) (sizeof (a) / sizeof (a)[0]) - /**************************************************************************** * Private Types ****************************************************************************/ @@ -1152,7 +1151,7 @@ int main(int argc, FAR char *argv[]) "assignments...\n", i ? 'f' : 's'); - for (t = 0; t < ARRAYSIZE(test_data); ++t) + for (t = 0; t < nitems(test_data); ++t) { /* Prefill the arguments with zeroes. */ @@ -1329,7 +1328,7 @@ int main(int argc, FAR char *argv[]) /* Test the char, short, and long specification-modifiers. */ printf("\nTesting scanf()'s type-modifiers...\n"); - for (t = 0; t < ARRAYSIZE(type_data); ++t) + for (t = 0; t < nitems(type_data); ++t) { unsigned char hhu; unsigned short hu; diff --git a/testing/sensortest/sensortest.c b/testing/sensortest/sensortest.c index 847db9523c..76c004b687 100644 --- a/testing/sensortest/sensortest.c +++ b/testing/sensortest/sensortest.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,6 @@ * Pre-processor Definitions ****************************************************************************/ -#define ARRAYSIZE(a) (sizeof(a) / sizeof(a)[0]) #define DEVNAME_FMT "/dev/uorb/sensor_%s" #define DEVNAME_MAX 64 @@ -317,7 +317,7 @@ int main(int argc, FAR char *argv[]) if (optind < argc) { name = argv[optind]; - for (idx = 0; idx < ARRAYSIZE(g_sensor_info); idx++) + for (idx = 0; idx < nitems(g_sensor_info); idx++) { if (!strncmp(name, g_sensor_info[idx].name, strlen(g_sensor_info[idx].name))) diff --git a/wireless/ieee802154/i8sak/i8sak_main.c b/wireless/ieee802154/i8sak/i8sak_main.c index f7ad5ebea5..f052dc0e01 100644 --- a/wireless/ieee802154/i8sak/i8sak_main.c +++ b/wireless/ieee802154/i8sak/i8sak_main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -102,8 +103,6 @@ static const struct i8sak_command_s g_i8sak_commands[] = {"tx", (CODE void *)i8sak_tx_cmd}, }; -#define NCOMMANDS (sizeof(g_i8sak_commands) / sizeof(struct i8sak_command_s)) - static sq_queue_t g_i8sak_free; static sq_queue_t g_i8sak_instances; static struct i8sak_s g_i8sak_pool[CONFIG_IEEE802154_I8SAK_NINSTANCES]; @@ -893,7 +892,7 @@ int main(int argc, FAR char *argv[]) /* Find the command in the g_i8sak_command[] list */ i8sakcmd = NULL; - for (i = 0; i < NCOMMANDS; i++) + for (i = 0; i < nitems(g_i8sak_commands); i++) { FAR const struct i8sak_command_s *cmd = &g_i8sak_commands[i]; if (strcmp(argv[argind], cmd->name) == 0) diff --git a/wireless/iwpan/src/iwpan.c b/wireless/iwpan/src/iwpan.c index 4c32ee3bf3..d4114a03bf 100644 --- a/wireless/iwpan/src/iwpan.c +++ b/wireless/iwpan/src/iwpan.c @@ -22,6 +22,7 @@ * Included Files ****************************************************************************/ +#include #include #include #include @@ -94,8 +95,6 @@ static const struct iwpan_command_s g_iwpan_commands[] = {"txpwr", 2, (CODE void *)iwpan_txpwr_cmd}, }; -#define NCOMMANDS (sizeof(g_iwpan_commands) / sizeof(struct iwpan_command_s)) - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -660,7 +659,7 @@ int main(int argc, FAR char *argv[]) /* Find the command in the g_iwpan_command[] list */ iwpancmd = NULL; - for (i = 0; i < NCOMMANDS; i++) + for (i = 0; i < nitems(g_iwpan_commands); i++) { FAR const struct iwpan_command_s *cmd = &g_iwpan_commands[i]; if (strcmp(cmdname, cmd->name) == 0) diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index 15c5eb89b2..f5b35142c9 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -137,8 +138,6 @@ static const struct wapi_command_s g_wapi_commands[] = * Pre-processor Definitions ****************************************************************************/ -#define NCOMMANDS (sizeof(g_wapi_commands) / sizeof(struct wapi_command_s)) - /* Maximum length of the PASSPHRASE, refer to IEEE802.11i specification */ #define PASSPHRASE_MAX_LEN (64) @@ -1200,7 +1199,7 @@ int main(int argc, FAR char *argv[]) /* Find the command in the g_wapi_command[] list */ wapicmd = NULL; - for (i = 0; i < NCOMMANDS; i++) + for (i = 0; i < nitems(g_wapi_commands); i++) { FAR const struct wapi_command_s *cmd = &g_wapi_commands[i]; if (strcmp(cmdname, cmd->name) == 0) From 28de04b3fb1986cb5b1c3f57c769da67dea4865f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 16 Aug 2023 01:18:05 +0800 Subject: [PATCH 2/3] Remove the definition of MIN/MAX use the macro in sys/params.h Signed-off-by: Xiang Xiao --- lte/alt1250/alt1250_util.h | 6 ++---- testing/drivertest/drivertest_audio.c | 5 +---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lte/alt1250/alt1250_util.h b/lte/alt1250/alt1250_util.h index 62108a1e35..edff6203fa 100644 --- a/lte/alt1250/alt1250_util.h +++ b/lte/alt1250/alt1250_util.h @@ -25,16 +25,14 @@ * Included Files ****************************************************************************/ +#include + #include "alt1250_daemon.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#ifndef MIN -# define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/testing/drivertest/drivertest_audio.c b/testing/drivertest/drivertest_audio.c index 6040bf17e7..9b7fe9d5ea 100644 --- a/testing/drivertest/drivertest_audio.c +++ b/testing/drivertest/drivertest_audio.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -50,10 +51,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef MAX -# define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif - #define OPTARG_TO_VALUE(value, type, base) \ do \ { \ From aa2965f71c95dfb761e18610c0827fabbdef2973 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 16 Aug 2023 01:41:18 +0800 Subject: [PATCH 3/3] Fix some coding style issue Signed-off-by: Xiang Xiao --- examples/ft80x/ft80x_main.c | 16 +++--- examples/pdcurses/testcurs_main.c | 43 +++++++++------- lte/alt1250/alt1250_util.h | 2 +- netutils/thttpd/mime_types.h | 2 +- netutils/thttpd/tdate_parse.c | 72 +++++++++++++++++---------- testing/crypto/hmac.c | 2 +- testing/drivertest/drivertest_audio.c | 2 +- 7 files changed, 82 insertions(+), 57 deletions(-) diff --git a/examples/ft80x/ft80x_main.c b/examples/ft80x/ft80x_main.c index c889197472..06a1111233 100644 --- a/examples/ft80x/ft80x_main.c +++ b/examples/ft80x/ft80x_main.c @@ -61,13 +61,13 @@ struct ft80x_exampleinfo_s * ft80x_prim_lines LINES Line drawing primitive * ft80x_prim_linestrip LINE_STRIP Line strip drawing primitive * ft80x_prim_edgestrip_r EDGE_STRIP_R Edge strip right side drawing - primitive + * primitive * (To be provided) EDGE_STRIP_L Edge strip left side drawing - primitive + * primitive * (To be provided) EDGE_STRIP_A Edge strip above side drawing - primitive + * primitive * (To be provided) EDGE_STRIP_B Edge strip below side drawing - primitive + * primitive * ft80x_prim_rectangles RECTS Rectangle drawing primitive * ft80x_prim_scissor SCISSOR Scissor primitive * ft80x_prim_stencil STENCIL Stencil primitives @@ -96,7 +96,7 @@ static const struct ft80x_exampleinfo_s g_primitives[] = * possible options. * * FUNCTION CoProc CMD USED DESCRIPTION - * ------------------------ --------------- ---------------------------------- + * ------------------------ --------------- -------------------------------- * ft80x_coproc_button CMD_BUTTON Draw a button * ft80x_coproc_clock CMD_CLOCK Draw an analog clock * ft80x_coproc_gauge CMD_GAUGE Draw a gauge @@ -109,12 +109,12 @@ static const struct ft80x_exampleinfo_s g_primitives[] = * ft80x_coproc_toggle CMD_TOGGLE Draw a toggle switch * ft80x_coproc_number CMD_NUMBER Draw a decimal number * ft80x_coproc_calibrate CMD_CALIBRATE Execute the touch screen - calibration routine + * calibration routine * ft80x_coproc_spinner CMD_SPINNER Start an animated spinner * ft80x_coproc_screensaver CMD_SCREENSAVER Start an animated screensaver * (To be provided) CMD_SKETCH Start a continuous sketch update * (To be provided) CMD_SNAPSHOT Take a snapshot of the current - screen + * screen * ft80x_coproc_logo CMD_LOGO Play device log animation */ @@ -180,7 +180,7 @@ static int ft80x_showname(int fd, FAR struct ft80x_dlbuffer_s *buffer, /* Clear the display */ cmds.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(0, 0, 0x80); - cmds.clear.cmd = FT80X_CLEAR(1 ,1, 1); + cmds.clear.cmd = FT80X_CLEAR(1, 1, 1); cmds.colorrgb.cmd = FT80X_COLOR_RGB(0xff, 0xff, 0xff); /* Use the CMD_TEXT co-processor command to show the name of the next diff --git a/examples/pdcurses/testcurs_main.c b/examples/pdcurses/testcurs_main.c index 14d2951d2f..abec88a9d9 100644 --- a/examples/pdcurses/testcurs_main.c +++ b/examples/pdcurses/testcurs_main.c @@ -33,10 +33,6 @@ #include "graphics/curses.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - #ifdef WACS_S1 # define HAVE_WIDE 1 #else @@ -49,6 +45,10 @@ # include #endif +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + #ifdef A_COLOR # define HAVE_COLOR 1 #else @@ -112,15 +112,15 @@ static const COMMAND command[] = {"Scroll Test", scroll_test}, {"Input Test", input_test}, {"Output Test", output_test}, - {"ACS Test", acs_test} + {"ACS Test", acs_test}, #if HAVE_COLOR - , {"Color Test", color_test} + {"Color Test", color_test}, #endif #if HAVE_CLIPBOARD - , {"Clipboard Test", clipboard_test} + {"Clipboard Test", clipboard_test}, #endif #if HAVE_WIDE - , {"Wide Input", wide_test} + {"Wide Input", wide_test}, #endif }; @@ -139,9 +139,9 @@ static const char *acs_names[] = "ACS_PLMINUS", "ACS_BULLET", "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW", - "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK" + "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK", #ifdef ACS_S3 - , "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL", + "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL", "ACS_PI", "ACS_NEQUAL", "ACS_STERLING" #endif }; @@ -240,6 +240,7 @@ static int init_test(WINDOW ** win, int argc, char *argv[]) start_color(); } #endif + /* Create a drawing window */ width = 60; @@ -357,7 +358,7 @@ static void input_test(WINDOW *win) sw = w / 3; sh = h / 3; - if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) + if (!(subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2))) { return; } @@ -679,7 +680,7 @@ static void output_test(WINDOW *win) wattron(win1, A_BLINK); mvwaddstr(win1, 4, 1, - "This blinking text should appear in only the second window"); + "This blinking text should appear in only the second window"); wattroff(win1, A_BLINK); mvwin(win1, by, bx); @@ -726,7 +727,7 @@ static void output_test(WINDOW *win) wclear(win); wmove(win, 2, 2); - wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it"); + wprintw(win, "This is a formatted string in a window: %d is it\n", 42); mvwaddstr(win, 10, 1, "Enter a string: "); wrefresh(win); echo(); @@ -890,7 +891,8 @@ static void clipboard_test(WINDOW *win) FAR struct pdc_context_s *ctx = PDC_ctx(); #endif - mvaddstr(1, 1, "This test will display the contents of the system clipboard"); + mvaddstr(1, 1, + "This test will display the contents of the system clipboard"); continue2(); @@ -923,7 +925,7 @@ static void clipboard_test(WINDOW *win) clear(); mvaddstr(1, 1, - "This test will place the following string in the system clipboard:"); + "This test will place the following string in the system clipboard:"); mvaddstr(2, 1, text); i = PDC_setclipboard(text, strlen(text)); @@ -1077,7 +1079,8 @@ static void color_test(WINDOW *win) for (j = 0; j < 16; j++) { mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4)); - mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD); + mvaddch(tmarg + i + 5, col3 + j, + fill | COLOR_PAIR(i + 4) | A_BOLD); } } @@ -1094,7 +1097,7 @@ static void color_test(WINDOW *win) short red; short green; short blue; - } orgcolors[16]; + }orgcolors[16]; int MAXCOL = (COLORS >= 16) ? 16 : 8; @@ -1130,7 +1133,8 @@ static void color_test(WINDOW *win) for (i = 0; i < MAXCOL; i++) { - init_color(i, orgcolors[i].red, orgcolors[i].green, orgcolors[i].blue); + init_color(i, orgcolors[i].red, + orgcolors[i].green, orgcolors[i].blue); } } } @@ -1175,7 +1179,8 @@ void display_menu(int old_option, int new_option) #ifdef CONFIG_PDCURSES_MULTITHREAD FAR struct pdc_context_s *ctx = PDC_ctx(); #endif - int lmarg = (COLS - 14) / 2, tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; + int lmarg = (COLS - 14) / 2; + int tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; if (old_option == -1) { diff --git a/lte/alt1250/alt1250_util.h b/lte/alt1250/alt1250_util.h index edff6203fa..85be0c992e 100644 --- a/lte/alt1250/alt1250_util.h +++ b/lte/alt1250/alt1250_util.h @@ -25,7 +25,7 @@ * Included Files ****************************************************************************/ -#include +#include #include "alt1250_daemon.h" diff --git a/netutils/thttpd/mime_types.h b/netutils/thttpd/mime_types.h index 6b6b290054..8889cd3f73 100644 --- a/netutils/thttpd/mime_types.h +++ b/netutils/thttpd/mime_types.h @@ -1,6 +1,6 @@ /**************************************************************************** * apps/netutils/thttpd/mime_types.h - * Provides mappings between filename extensions and MIME types and encodings. + * Provides mappings between filename extensions, MIME types and encodings. * * Based on mime_encodings.txt and mime_types.txt by Jef Poskanser which * contained no copyright information. diff --git a/netutils/thttpd/tdate_parse.c b/netutils/thttpd/tdate_parse.c index 995af3a950..3622ffe972 100644 --- a/netutils/thttpd/tdate_parse.c +++ b/netutils/thttpd/tdate_parse.c @@ -91,7 +91,7 @@ static int strlong_compare(const void *v1, const void *v2) #endif #ifdef HAVE_DAY_OF_WEEK /* Day of week not yet supported by NuttX */ -static int strlong_search(char *str, struct strlong *tab, int n, long *lP) +static int strlong_search(char *str, struct strlong *tab, int n, long *lp) { int i; int h; @@ -114,7 +114,7 @@ static int strlong_search(char *str, struct strlong *tab, int n, long *lP) } else { - *lP = tab[i].l; + *lp = tab[i].l; return 1; } @@ -127,16 +127,24 @@ static int strlong_search(char *str, struct strlong *tab, int n, long *lP) #endif #ifdef HAVE_DAY_OF_WEEK /* Day of week not yet supported by NuttX */ -static int scan_wday(char *str_wday, long *tm_wdayP) +static int scan_wday(char *str_wday, long *tm_wdayp) { - static struct strlong wday_tab[] = { - {"sun", 0}, {"sunday", 0}, - {"mon", 1}, {"monday", 1}, - {"tue", 2}, {"tuesday", 2}, - {"wed", 3}, {"wednesday", 3}, - {"thu", 4}, {"thursday", 4}, - {"fri", 5}, {"friday", 5}, - {"sat", 6}, {"saturday", 6}, + static struct strlong wday_tab[] = + { + {"sun", 0}, + {"sunday", 0}, + {"mon", 1}, + {"monday", 1}, + {"tue", 2}, + {"tuesday", 2}, + {"wed", 3}, + {"wednesday", 3}, + {"thu", 4}, + {"thursday", 4}, + {"fri", 5}, + {"friday", 5}, + {"sat", 6}, + {"saturday", 6}, }; static int sorted = 0; @@ -149,26 +157,38 @@ static int scan_wday(char *str_wday, long *tm_wdayP) } pound_case(str_wday); - return strlong_search(str_wday, wday_tab, nitems(wday_tab), tm_wdayP); + return strlong_search(str_wday, wday_tab, nitems(wday_tab), tm_wdayp); } #endif /* Day of week not yet supported by NuttX */ #ifdef TDATE_PARSE_WORKS -static int scan_mon(char *str_mon, long *tm_monP) +static int scan_mon(char *str_mon, long *tm_monp) { - static struct strlong mon_tab[] = { - {"jan", 0}, {"january", 0}, - {"feb", 1}, {"february", 1}, - {"mar", 2}, {"march", 2}, - {"apr", 3}, {"april", 3}, + static struct strlong mon_tab[] = + { + {"jan", 0}, + {"january", 0}, + {"feb", 1}, + {"february", 1}, + {"mar", 2}, + {"march", 2}, + {"apr", 3}, + {"april", 3}, {"may", 4}, - {"jun", 5}, {"june", 5}, - {"jul", 6}, {"july", 6}, - {"aug", 7}, {"august", 7}, - {"sep", 8}, {"september", 8}, - {"oct", 9}, {"october", 9}, - {"nov", 10}, {"november", 10}, - {"dec", 11}, {"december", 11}, + {"jun", 5}, + {"june", 5}, + {"jul", 6}, + {"july", 6}, + {"aug", 7}, + {"august", 7}, + {"sep", 8}, + {"september", 8}, + {"oct", 9}, + {"october", 9}, + {"nov", 10}, + {"november", 10}, + {"dec", 11}, + {"december", 11}, }; static int sorted = 0; @@ -181,7 +201,7 @@ static int scan_mon(char *str_mon, long *tm_monP) } pound_case(str_mon); - return strlong_search(str_mon, mon_tab, nitems(mon_tab), tm_monP); + return strlong_search(str_mon, mon_tab, nitems(mon_tab), tm_monp); } #endif diff --git a/testing/crypto/hmac.c b/testing/crypto/hmac.c index cbad8decb1..a90762da51 100644 --- a/testing/crypto/hmac.c +++ b/testing/crypto/hmac.c @@ -193,7 +193,7 @@ int main(void) { char output[32]; int ret = 0; - for (int i = 0; i < nitems(testcase) i++) + for (int i = 0; i < nitems(testcase); i++) { ret += syshmac(CRYPTO_MD5_HMAC, testcase[i].key, testcase[i].keylen, diff --git a/testing/drivertest/drivertest_audio.c b/testing/drivertest/drivertest_audio.c index 9b7fe9d5ea..e7b10981ca 100644 --- a/testing/drivertest/drivertest_audio.c +++ b/testing/drivertest/drivertest_audio.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include