From 5474f563c874ae485f0da213743f2fb19321890e Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 19 Jan 2021 11:30:08 +0100 Subject: [PATCH] software/bios/readline: Use unsigned int for small numbers There is no need to use "unsigned long" for small numbers related to the number of characters in a line. Use "unsigned int" instead. This allows us to drop the casts when calling putnstr(), and fixes compiler warnings on 64-bit for callsites where the casts were missing: warning: field precision specifier '.*' expects argument of type 'int', but argument 2 has type 'long unsigned int' Reported-by: Gabriel Somlo Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/readline.c | 18 +++++++++--------- litex/soc/software/bios/readline.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/litex/soc/software/bios/readline.c b/litex/soc/software/bios/readline.c index 48d8f1a6c..f507f1a65 100644 --- a/litex/soc/software/bios/readline.c +++ b/litex/soc/software/bios/readline.c @@ -150,10 +150,10 @@ void hist_init(void) } #endif -static void cread_add_char(char ichar, int insert, unsigned long *num, - unsigned long *eol_num, char *buf, unsigned long len) +static void cread_add_char(char ichar, int insert, unsigned int *num, + unsigned int *eol_num, char *buf, unsigned int len) { - unsigned long wlen; + unsigned int wlen; if (insert || *num == *eol_num) { if (*eol_num > len - 1) { @@ -186,9 +186,9 @@ static void cread_add_char(char ichar, int insert, unsigned long *num, int readline(char *buf, int len) { - unsigned long num = 0; - unsigned long eol_num = 0; - unsigned long wlen; + unsigned int num = 0; + unsigned int eol_num = 0; + unsigned int wlen; int insert = 1; char ichar; @@ -254,7 +254,7 @@ int readline(char *buf, int len) wlen = eol_num - num - 1; if (wlen) { memmove(&buf[num], &buf[num+1], wlen); - putnstr(buf + num, (int)wlen); + putnstr(buf + num, wlen); } getcmd_putch(' '); @@ -286,7 +286,7 @@ int readline(char *buf, int len) num--; memmove(buf + num, buf + num + 1, wlen); getcmd_putch(CTL_BACKSPACE); - putnstr(buf + num, (int)wlen); + putnstr(buf + num, wlen); getcmd_putch(' '); do { getcmd_putch(CTL_BACKSPACE); @@ -298,7 +298,7 @@ int readline(char *buf, int len) if (num < eol_num) { wlen = eol_num - num; memmove(buf + num, buf + num + 1, wlen); - putnstr(buf + num, (int)(wlen - 1)); + putnstr(buf + num, wlen - 1); getcmd_putch(' '); do { getcmd_putch(CTL_BACKSPACE); diff --git a/litex/soc/software/bios/readline.h b/litex/soc/software/bios/readline.h index f1284c5d1..290b2e2c0 100644 --- a/litex/soc/software/bios/readline.h +++ b/litex/soc/software/bios/readline.h @@ -72,7 +72,7 @@ struct esc_cmds { #define REFRESH_TO_EOL() { \ if (num < eol_num) { \ wlen = eol_num - num; \ - putnstr(buf + num, (int)wlen); \ + putnstr(buf + num, wlen); \ num = eol_num; \ } \ }