From: mar Date: Mon, 26 Dec 1988 14:37:27 +0000 (+0000) Subject: deal with ^D in input, don't return a pointer into the stack, don't X-Git-Tag: KREL1~42 X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/12487417d281bcdce3c79f65b55438555987d149 deal with ^D in input, don't return a pointer into the stack, don't malloc unneeded memory --- diff --git a/clients/passwd/chfn.c b/clients/passwd/chfn.c index 332ada02..004e714f 100644 --- a/clients/passwd/chfn.c +++ b/clients/passwd/chfn.c @@ -230,7 +230,7 @@ char *ask(question, def_val, phone_num) char *def_val; int phone_num; /* True if this must contain only digits */ { - char buf[BUFSIZ]; + static char buf[BUFSIZ]; int ok = FALSE; char *result; int i; @@ -242,7 +242,8 @@ char *ask(question, def_val, phone_num) { ok = TRUE; printf("%s [%s]: ", question, def_val); - (void) fgets(buf, sizeof(buf), stdin); + if (fgets(buf, sizeof(buf), stdin) == NULL) + leave(0); buf[strlen(buf) - 1] = NULL; if (strlen(buf) == 0) result = def_val; @@ -292,11 +293,9 @@ char *ask(question, def_val, phone_num) } /* Remove dashes if necessary */ - if (dashes) { + if (dashes && result == buf) { char *tmp1, *tmp2; - result = strsave(buf); - tmp1 = (char *)buf; - tmp2 = result; + tmp1 = tmp2 = (char *)buf; do { if (*(tmp1) != '-') *(tmp2++) = *(tmp1);