[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getpass.c



Yves Pelletier <ypell@cam.org> writes:

|> Background: this loop is part of a routine that takes a string
|> from a tty, then strips the trailing end-of-line character.
|> I modified it to do the same thing if it encounters an EOF:

|> 	{
|> 	  /* zap the newline; if we get an EOF instead, 
|>              we zap that, too. */
|> 	  l = strlen(buf);
|> 	  if (buf[l-1] != '\n') {
|> 	    while (((c = fgetc(tty)) != '\n') && ((int) c != EOF))
                                                  ^^^^^
This cast is unnecessary and misleading, it should be removed.  If `c' is
declared `char' then it is a bad bug that should be fixed RSN.

|> 	      /* wait for a newline or an EOF */ ;
|> 	  }
|> 	  if (l > PASS_MAX)
|> 	    buf[PASS_MAX] = '\0';
|> 	  else if ((buf[l-1] == '\n') || ((int) buf[l-1] == EOF)) 
                                         ^^^^^^^^^^^^^^^^^^^^^^
It doesn't make sense to check for EOF in a string, because no character
can ever have the value EOF.

|> 	    buf[l-1] = '\0';
|> 	}

Andreas.