getpass fgets check

Rich Felker dalias at
Fri Dec 23 01:27:31 UTC 2011

On Wed, Dec 21, 2011 at 10:53:30AM +1000, Daniel Wainwright wrote:
> I don't believe that buf is guaranteed to be unchanged if there is an error
> in fgets, according to the man page the contents are "indeterminate". So it
> may write some characters to buf and not null-terminate it. So if you're
> only assuming fgets conforms to the spec I think checking the return value
> is safer, or is this an implementation detail of this fgets?

Can you show me anywhere the C standard allows crap to be written to
the buffer? fgets is specified very simply as if by a sequence of
calls to fgetc filling subsequent positions of the pointed-to array.
It can't act outside of those bounds...


More information about the uClibc mailing list