From 3c2592be045f1bf3cc35b7000d280afaa551d7df Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 6 Nov 2025 09:59:43 -0600 Subject: [PATCH] cpukit/libmisc/shell: Correct comparisons of different signedness The GCC warning -Wsign-compare flagged these instances of comparing signed and unsigned types. A common pair was size_t and int. --- cpukit/libmisc/shell/main_df.c | 4 ++-- cpukit/libmisc/shell/main_drvmgr.c | 2 +- cpukit/libmisc/shell/main_flashdev.c | 2 +- cpukit/libmisc/shell/main_help.c | 4 ++-- cpukit/libmisc/shell/main_i2cset.c | 2 +- cpukit/libmisc/shell/main_ls.c | 10 +++++++--- cpukit/libmisc/shell/shell.c | 10 +++++----- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cpukit/libmisc/shell/main_df.c b/cpukit/libmisc/shell/main_df.c index 683237b0b4..07823cbed3 100644 --- a/cpukit/libmisc/shell/main_df.c +++ b/cpukit/libmisc/shell/main_df.c @@ -39,7 +39,7 @@ static unsigned rtems_shell_df_parse_size(const char *str) { unsigned result; char suffix; - int i; + size_t i; if (sscanf(str, "%d%c", &result, &suffix) == 2) { @@ -61,7 +61,7 @@ static unsigned rtems_shell_df_parse_size(const char *str) static char *rtems_shell_df_humanize_size(uint64_t block_size, char *buf, size_t size) { - int i = 0; + size_t i = 0; while (block_size >= 1024 && i < sizeof(suffixes) / sizeof(suffixes[0]) - 1) { diff --git a/cpukit/libmisc/shell/main_drvmgr.c b/cpukit/libmisc/shell/main_drvmgr.c index 95e0eb7d0c..5c12bc86bc 100644 --- a/cpukit/libmisc/shell/main_drvmgr.c +++ b/cpukit/libmisc/shell/main_drvmgr.c @@ -354,7 +354,7 @@ static int shell_drvmgr_translate(int argc, char *argv[]) rc = drvmgr_translate((struct drvmgr_dev *)obj, up | rev, (void *)src, &dst); if (rc == 0) printf(" Address %p could not be translated\n", (void *)src); - else if (rc == 0xffffffff) + else if (rc == (int) 0xffffffffU) printf(" %p => %p (no translation required)\n", (void *)src, dst); else printf(" %p => %p (map size 0x%x)\n", (void *)src, dst, rc); diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index 516a68e53b..d98cd777aa 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -213,7 +213,7 @@ int flashdev_shell_read( /* Print buffer out in 32bit blocks */ printf("Reading %s at 0x%08x for 0x%x bytes\n", dev_path, address, bytes); - for (int i = 0; i < (bytes/4); i++) { + for (size_t i = 0; i < (bytes/4); i++) { printf("%08x ", ((uint32_t*)buffer)[i]); if ((i+1)%4 == 0) { printf("\n"); diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c index f9573c53a6..bd43aee98c 100644 --- a/cpukit/libmisc/shell/main_help.c +++ b/cpukit/libmisc/shell/main_help.c @@ -149,7 +149,7 @@ static int rtems_shell_help( if (!col){ col = printf(" %s",topic->topic); } else { - if ((col+strlen(topic->topic)+2)>(cols - 2)){ + if ((col+(int)strlen(topic->topic)+2)>(cols - 2)){ printf("\n"); col = printf(" %s",topic->topic); } else { @@ -165,7 +165,7 @@ static int rtems_shell_help( shell_cmd = rtems_shell_first_cmd; while (shell_cmd) { size_t len = strlen(shell_cmd->name); - if (len > indent) { + if ((int)len > indent) { indent = len; } shell_cmd = shell_cmd->next; diff --git a/cpukit/libmisc/shell/main_i2cset.c b/cpukit/libmisc/shell/main_i2cset.c index 9e709c6cd7..c34764dece 100644 --- a/cpukit/libmisc/shell/main_i2cset.c +++ b/cpukit/libmisc/shell/main_i2cset.c @@ -54,7 +54,7 @@ rtems_i2cset_shell_main(int argc, char *argv[]) /* Necessary: data-address and values. This will be a bit more. */ uint8_t writebuff[argc]; size_t len; - size_t i; + int i; i2c_msg msgs[] = {{ .flags = 0, .buf = writebuff, diff --git a/cpukit/libmisc/shell/main_ls.c b/cpukit/libmisc/shell/main_ls.c index 7e8edab68c..6dcca6e91b 100644 --- a/cpukit/libmisc/shell/main_ls.c +++ b/cpukit/libmisc/shell/main_ls.c @@ -516,8 +516,12 @@ display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list) DISPLAY d; FTSENT *cur; NAMES *np; - u_int64_t btotal, stotal, maxblock, maxsize; - int maxinode, maxnlink, maxmajor, maxminor; + u_int64_t btotal, stotal, maxsize; + blkcnt_t maxblock; + ino_t maxinode; + rtems_device_major_number maxmajor; + rtems_device_minor_number maxminor; + int maxnlink; int bcfile, entries, flen, glen, ulen, maxflags, maxgroup, maxlen; int maxuser, needstats; const char *user, *group; @@ -666,7 +670,7 @@ display(rtems_shell_ls_globals* globals, FTSENT *p, FTSENT *list) } d.s_flags = maxflags; d.s_group = maxgroup; - (void)snprintf(buf, sizeof(buf), "%u", maxinode); + (void)snprintf(buf, sizeof(buf), "%llu", maxinode); d.s_inode = strlen(buf); (void)snprintf(buf, sizeof(buf), "%u", maxnlink); d.s_nlink = strlen(buf); diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c index 7aeec815de..17c4e9c253 100644 --- a/cpukit/libmisc/shell/shell.c +++ b/cpukit/libmisc/shell/shell.c @@ -360,7 +360,7 @@ static int rtems_shell_line_editor( extended_key = rtems_shell_getchar(in); - if (extended_key == EOF) + if ((int)extended_key == EOF) return -2; c = extended_key & RTEMS_SHELL_KEYS_NORMAL_MASK; @@ -451,7 +451,7 @@ static int rtems_shell_line_editor( case 4: /* Control-D */ if (strlen(line)) { - if (col < strlen(line)) { + if (col < (int)strlen(line)) { rtems_shell_move_left(line + col, 1); if (out != NULL) { int bs; @@ -620,7 +620,7 @@ static int rtems_shell_line_editor( if (col > 0) { char tmp; - if (col == strlen(line)) { + if (col == (int)strlen(line)) { col--; if (out != NULL) fprintf(out,"\b"); @@ -643,7 +643,7 @@ static int rtems_shell_line_editor( /* strlen() returns size_t but fprintf("%*...") below requires * int! */ int clen = (int) strlen (line); - int bs; + size_t bs; rtems_shell_move_left(line, col); if (out != NULL) { @@ -1105,7 +1105,7 @@ static bool shell_main_loop( } if (cmd_argv && cmds[0]) { - size_t cmd; + ssize_t cmd; memset (cmds[0], 0, cmd_count * RTEMS_SHELL_CMD_SIZE);