From 5ca8c0ba635c9668e43a37b4706efa3e6a6b4c8b Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Sun, 17 Dec 1995 20:58:55 +0000 Subject: (getpass): Don't barf if getline returns a null BUF. --- misc/getpass.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'misc/getpass.c') diff --git a/misc/getpass.c b/misc/getpass.c index bea2ac0..16f4a3a 100644 --- a/misc/getpass.c +++ b/misc/getpass.c @@ -74,16 +74,17 @@ getpass (prompt) /* Read the password. */ nread = __getline (&buf, &bufsize, in); - if (nread < 0 && buf != NULL) - buf[0] = '\0'; - else if (buf[nread - 1] == '\n') - { - /* Remove the newline. */ - buf[nread - 1] = '\0'; - if (echo_off) - /* Write the newline that was not echoed. */ - putc ('\n', out); - } + if (buf != NULL) + if (nread < 0) + buf[0] = '\0'; + else if (buf[nread - 1] == '\n') + { + /* Remove the newline. */ + buf[nread - 1] = '\0'; + if (echo_off) + /* Write the newline that was not echoed. */ + putc ('\n', out); + } /* Restore echoing. */ if (echo_off) -- cgit v1.1