Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 14 Feb 2019 02:19:09 +0300
From: Alexey Izbyshev <izbyshev@...ras.ru>
To: musl@...ts.openwall.com
Cc: Rich Felker <dalias@...ifal.cx>
Subject: Re: Bug in gets function?

On 2019-02-14 01:13, Rich Felker wrote:
> On Thu, Feb 14, 2019 at 12:39:07AM +0300, Alexey Izbyshev wrote:
>> On 2019-02-12 19:30, Rich Felker wrote:
>> >Here's an alternate proposal via direct implementation:
>> >
>> >char *gets(char *s)
>> >{
>> >	size_t i=0;
>> >	int c;
>> >	FLOCK(stdin);
>> >	while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c;
>> >	s[i] = 0;
>> >	if (c != '\n' && !feof(stdin)) s = 0;
>> >	FUNLOCK(stdin);
>> >	return s;
>> >}
>> >
>> >Does this look ok? Of course it's slow compared to a fgets-like
>> >operation on the buffer, but gets is not a usable interface and I
>> >don't see any reason to care whether it's fast.
>> >
>> gets() must also return NULL if EOF is reached and no bytes were read.
> 
> So if (c != '\n' && (!feof(stdin) || !i)) ?
> 
Yes, looks good.

Alexey

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.