No valgrind error on simple line-oriented session - iomenu - interactive terminal-based selection menu
 (HTM) git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8be6c99abe504ab6090d28a65d19c0c83bb36e75
 (DIR) parent 9bdaa10a695ec2d8a9890c980bd5b44d5ff6f48c
 (HTM) Author: Josuah Demangeonā  ā µ <mail@josuah.net>
       Date:   Sat, 18 Mar 2017 11:04:08 +0100
       
       No valgrind error on simple line-oriented session
       
       Diffstat:
         M Makefile                            |       2 +-
         M iomenu.c                            |      22 +++++-----------------
       
       2 files changed, 6 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       @@ -1,4 +1,4 @@
       -CFLAGS    = -std=c99 -Wpedantic -Wall -Wextra -g -static -O0
       +CFLAGS    = -std=c99 -Wpedantic -Wall -Wextra -g # -static 
        OBJ       = ${SRC:.c=.o}
        
        all: clean iomenu
 (DIR) diff --git a/iomenu.c b/iomenu.c
       @@ -144,7 +144,7 @@ filter_lines(void)
        int
        matching_prev(int pos)
        {
       -        for (size_t i = pos - 1; i > 0; i--)
       +        for (int i = pos - 1; i >= 0; i--)
                        if (linev[i]->match)
                                return i;
                return pos;
       @@ -326,11 +326,6 @@ input_key(FILE *tty_fp)
        
                char key = fgetc(tty_fp);
        
       -        if (key == '\n') {
       -                print_selection();
       -                return EXIT_SUCCESS;
       -        }
       -
                switch (key) {
        
                case CONTROL('C'):
       @@ -409,7 +404,7 @@ input_get(int tty_fd)
        void
        usage(void)
        {
       -        fputs("usage: iomenu [-n] [-p prompt] [-l lines]\n", stderr);
       +        fputs("usage: iomenu [-l lines] [-p prompt]\n", stderr);
        
                exit(EXIT_FAILURE);
        }
       @@ -420,19 +415,18 @@ main(int argc, char *argv[])
        {
                int i, exit_code, tty_fd = open("/dev/tty", O_RDWR);
        
       -        /* command line arguments */
                for (i = 1; i < argc; i++) {
                        if (argv[i][0] != '-' || strlen(argv[i]) != 2)
                                usage();
        
                        switch (argv[i][1]) {
                        case 'l':
       -                        if (sscanf(argv[++i], "%d", &opt_lines) <= 0)
       -                                die("wrong number format after -l");
       +                        if (++i >= argc || sscanf(argv[i], "%d", &opt_lines) <= 0)
       +                                usage();
                                break;
                        case 'p':
                                if (++i >= argc)
       -                                die("missing string after -p");
       +                                usage();
                                opt_prompt = argv[i];
                                break;
                        default:
       @@ -440,18 +434,12 @@ main(int argc, char *argv[])
                        }
                }
        
       -        /* command line arguments */
                read_lines();
        
       -        /* set the interface */
                print_screen(tty_fd);
       -
       -        /* listen and interact to input */
                exit_code = input_get(tty_fd);
        
                print_clear(opt_lines);
       -
       -        /* close files descriptors and pointers, and free memory */
                close(tty_fd);
                free_linev(linev);