diff options
author | Carl Worth <cworth@cworth.org> | 2009-12-01 08:06:09 -0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-12-01 08:06:09 -0800 |
commit | eb0cf86c7a9d5cda464d4d36a9cac66f26b5529d (patch) | |
tree | 140439cdd9d4d567f83ad4ac7747c40c1d2c5bb2 | |
parent | 5f0b2ece161b16321792d9ff2f76bcc33a3b6b42 (diff) |
notmuch setup: Exit if EOF is encountered at any prompt.
If the user is explicitly providing EOF, then terminating the program
is the most likely desired thing to do. This also avoids undefined
behavior from continuing with an uninitialized response after ignoring
the return value of getline().
-rw-r--r-- | notmuch-setup.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/notmuch-setup.c b/notmuch-setup.c index 5ec176d..622bbaa 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -100,12 +100,15 @@ notmuch_setup_command (unused (void *ctx), unsigned int i; int is_new; -#define prompt(format, ...) \ - do { \ - printf (format, ##__VA_ARGS__); \ - fflush (stdout); \ - getline (&response, &response_size, stdin); \ - chomp_newline (response); \ +#define prompt(format, ...) \ + do { \ + printf (format, ##__VA_ARGS__); \ + fflush (stdout); \ + if (getline (&response, &response_size, stdin) < 0) { \ + printf ("Exiting.\n"); \ + exit (1); \ + } \ + chomp_newline (response); \ } while (0) config = notmuch_config_open (ctx, NULL, &is_new); |