Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190213221330.GR23599@brightrain.aerifal.cx>
Date: Wed, 13 Feb 2019 17:13:30 -0500
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: Bug in gets function?

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)) ?

Rich

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.