]> diplodocus.org Git - nmh/blobdiff - sbr/read_switch_multiword_via_readline.c
Fix invalid pointer arithmetic.
[nmh] / sbr / read_switch_multiword_via_readline.c
index 8696c57fd33bce3ad148e4dffb5a6b9a6db19d44..0c099c565240e70b855c72d57bd14fc8f96b7237 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * read_switch_multiword_via_readline.c -- get an answer from the user, with readline
+/* read_switch_multiword_via_readline.c -- get an answer from the user, with readline
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -43,7 +41,7 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
            return NULL;
 
        if (ans[0] == '?' || ans[0] == '\0') {
-           printf("Options are:\n");
+           puts("Options are:");
            print_sw(ALL, ansp, "", stdout);
            free(ans);
            continue;
@@ -51,6 +49,8 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
        add_history(ans);
        strncpy(ansbuf, ans, sizeof(ansbuf));
        ansbuf[sizeof(ansbuf) - 1] = '\0';
+        free(ans);
+
        cpp = brkstring(ansbuf, " ", NULL);
        switch (smatch(*cpp, ansp)) {
            case AMBIGSW:
@@ -60,10 +60,8 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
                printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
                continue;
            default:
-               free(ans);
                return cpp;
        }
-       free(ans);
     }
 }
 
@@ -77,16 +75,12 @@ initialize_readline(void)
 static char **
 nmh_completion(const char *text, int start, int end)
 {
-    char **matches;
-
     NMH_UNUSED (end);
 
-    matches = (char **) NULL;
-
     if (start == 0)
-       matches = rl_completion_matches(text, nmh_command_generator);
+       return rl_completion_matches(text, nmh_command_generator);
 
-    return matches;
+    return NULL;
 }
 
 static char *
@@ -113,4 +107,3 @@ nmh_command_generator(const char *text, int state)
     return NULL;
 }
 #endif /* READLINE_SUPPORT */
-