]> andersk Git - moira.git/commitdiff
deal with ^D in input, don't return a pointer into the stack, don't
authormar <mar>
Mon, 26 Dec 1988 14:37:27 +0000 (14:37 +0000)
committermar <mar>
Mon, 26 Dec 1988 14:37:27 +0000 (14:37 +0000)
malloc unneeded memory

clients/passwd/chfn.c

index 332ada02b539c187ab2d010d5e0ac1c757a62c46..004e714f96290f1af272fc6b238c24a04cfe5851 100644 (file)
@@ -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);
This page took 0.42852 seconds and 5 git commands to generate.