diff --git a/stand/libsa/gets.c b/stand/libsa/gets.c index 9172ffc1328f..206a6d25fcea 100644 --- a/stand/libsa/gets.c +++ b/stand/libsa/gets.c @@ -44,8 +44,11 @@ ngets(char *buf, int n) int c; char *lp; - for (lp = buf;;) - switch (c = getchar() & 0177) { + for (lp = buf;;) { + c = getchar(); + if (c == -1) + break; + switch (c & 0177) { case '\n': case '\r': *lp = '\0'; @@ -79,6 +82,7 @@ ngets(char *buf, int n) putchar(c); } } + } /*NOTREACHED*/ }