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

Ian Abbott abbotti at mev.co.uk
Tue Aug 8 03:07:54 PDT 2017


On 08/08/17 08:51, Lucas Stach wrote:
> Am Montag, den 07.08.2017, 18:10 -0400 schrieb Gaël PORTAY:
>> The getc function may return an errno code if an error happens.
>>
>> This patch prevents readline from printing a non printable character and
>> from looping to infinity and beyong.
>>
>> Signed-off-by: Gaël PORTAY <gael.portay at savoirfairelinux.com>
>> ---
>>   lib/readline_simple.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> 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?

And also change the type of the 'c' variable, as it is currently a plain 
'char'?

> Regards,
> Lucas

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti at mev.co.uk> )=-
-=(                          Web: http://www.mev.co.uk/  )=-



More information about the barebox mailing list