[PATCH 1/2] readline_simple: return -1 if getc fails

Gaël PORTAY gael.portay at savoirfairelinux.com
Tue Aug 8 09:14:09 PDT 2017


On Tue, Aug 08, 2017 at 05:36:14PM +0200, Lucas Stach wrote:
> Am Dienstag, den 08.08.2017, 11:20 -0400 schrieb Gaël PORTAY:
> > Hi Lucas,
> > 
> > On Tue, Aug 08, 2017 at 09:51:54AM +0200, Lucas Stach wrote:
> > > > diff --git a/lib/readline_simple.c b/lib/readline_simple.c
> > > > index c4d3d240e..1283c9602 100644
> > > > --- a/lib/readline_simple.c
> > > > +++ b/lib/readline_simple.c
> > > > @@ -58,6 +58,8 @@ int readline (const char *prompt, char *line, int len)
> > > >  
> > > >  	for (;;) {
> > > >  		c = getchar();
> > > > +		if (c < 0)
> > > > +			return (-1);
> > > 
> > > I don't like made up error codes. Is there any reason why we couldn't
> > > just pass through the negative error code from getchar?
> > > 
> > 
> > The thing here is that getchar() may return an error, and that error is not
> > tested. This causes readline to print the character 0xea (-EINVAL) which is not
> > printable.
> 
> So why wouldn't the following fix the issue?
> 
> signed char c;
> 
> if (c < 0)
> 	return c;
> 

Okay. I do prefer your solution.

I returned -1 mainly because the function comment says it returns -1 when it
breaks; and because parser.c and hush.c test readline function against -1 and
not against a negative value.

Also readline returns -1 if character is 0x03. Maybe it should return -EINTR;
-1 is EPERM: Operation not permitted.



More information about the barebox mailing list