mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] readline_simple: Fix compiler warning
@ 2021-05-12  5:44 Sascha Hauer
  2021-05-12 11:25 ` Michael Olbrich
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2021-05-12  5:44 UTC (permalink / raw)
  To: Barebox List

char is an unsigned type. To test the getchar() return value against
negative values we have to use a signed type. Use int instead.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/readline_simple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/readline_simple.c b/lib/readline_simple.c
index fcdbca41a9..2e52bfc2a0 100644
--- a/lib/readline_simple.c
+++ b/lib/readline_simple.c
@@ -44,7 +44,7 @@ int readline (const char *prompt, char *line, int len)
 	int	n = 0;				/* buffer index		*/
 	int	plen = 0;			/* prompt length	*/
 	int	col;				/* output column cnt	*/
-	char	c;
+	int	c;
 
 	/* print prompt */
 	if (prompt) {
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] readline_simple: Fix compiler warning
  2021-05-12  5:44 [PATCH] readline_simple: Fix compiler warning Sascha Hauer
@ 2021-05-12 11:25 ` Michael Olbrich
  2021-05-12 13:04   ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Olbrich @ 2021-05-12 11:25 UTC (permalink / raw)
  To: barebox; +Cc: Sascha Hauer

On Wed, May 12, 2021 at 07:44:40AM +0200, Sascha Hauer wrote:
> char is an unsigned type.

That's incorrect. In the C standard it is explicitly undefined whether char
is signed or unsigned. gcc implements this differently depending on the
architecture. I think ARM and x86 differ here.

Michael

> To test the getchar() return value against
> negative values we have to use a signed type. Use int instead.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  lib/readline_simple.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/readline_simple.c b/lib/readline_simple.c
> index fcdbca41a9..2e52bfc2a0 100644
> --- a/lib/readline_simple.c
> +++ b/lib/readline_simple.c
> @@ -44,7 +44,7 @@ int readline (const char *prompt, char *line, int len)
>  	int	n = 0;				/* buffer index		*/
>  	int	plen = 0;			/* prompt length	*/
>  	int	col;				/* output column cnt	*/
> -	char	c;
> +	int	c;
>  
>  	/* print prompt */
>  	if (prompt) {
> -- 
> 2.29.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] readline_simple: Fix compiler warning
  2021-05-12 11:25 ` Michael Olbrich
@ 2021-05-12 13:04   ` Sascha Hauer
  2021-05-12 15:15     ` Jules Maselbas
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2021-05-12 13:04 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: barebox

On Wed, May 12, 2021 at 01:25:14PM +0200, Michael Olbrich wrote:
> On Wed, May 12, 2021 at 07:44:40AM +0200, Sascha Hauer wrote:
> > char is an unsigned type.
> 
> That's incorrect. In the C standard it is explicitly undefined whether char
> is signed or unsigned. gcc implements this differently depending on the
> architecture. I think ARM and x86 differ here.

Ok. I already reworded this to "char can be an unsigned type".

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] readline_simple: Fix compiler warning
  2021-05-12 13:04   ` Sascha Hauer
@ 2021-05-12 15:15     ` Jules Maselbas
  0 siblings, 0 replies; 4+ messages in thread
From: Jules Maselbas @ 2021-05-12 15:15 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Michael Olbrich, barebox

FYI,

On Wed, May 12, 2021 at 03:04:30PM +0200, Sascha Hauer wrote:
> On Wed, May 12, 2021 at 01:25:14PM +0200, Michael Olbrich wrote:
> > On Wed, May 12, 2021 at 07:44:40AM +0200, Sascha Hauer wrote:
> > > char is an unsigned type.
> > 
> > That's incorrect. In the C standard it is explicitly undefined whether char
> > is signed or unsigned. gcc implements this differently depending on the
> > architecture. I think ARM and x86 differ here.
> 
> Ok. I already reworded this to "char can be an unsigned type".
You can use "singed char" if you really need it.

    There are five standard signed integer types, designated as signed char,
    short int, int, long int, and long long int.

from ISO/IEC 9899:TC2 - 6.2.5 Types

Best,
Jules


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-12 15:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  5:44 [PATCH] readline_simple: Fix compiler warning Sascha Hauer
2021-05-12 11:25 ` Michael Olbrich
2021-05-12 13:04   ` Sascha Hauer
2021-05-12 15:15     ` Jules Maselbas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox