diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2015-09-10 18:08:42 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-09-10 18:08:42 -0700 |
commit | 025b45b91ee3cbedfa99d02c414ecfe4756cdd1f (patch) | |
tree | dde0f1199b987e0d9a9fa1a0bf5eba8ff7e439d8 | |
parent | 31d1e04301f9266aa040a78030992fdaa5995e6e (diff) |
Don't crash on complete -C in non-interactive mode
Fixes #2361
-rw-r--r-- | src/builtin.h | 2 | ||||
-rw-r--r-- | src/builtin_complete.cpp | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/builtin.h b/src/builtin.h index e2a9478e..3a160195 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -25,7 +25,7 @@ enum /** Error message on missing argument */ -#define BUILTIN_ERR_MISSING _( L"%ls: Expected argument\n" ) +#define BUILTIN_ERR_MISSING _( L"%ls: Expected argument for option %ls\n" ) /** Error message on invalid combination of options diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 6c4ccbcb..e206f9ab 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -433,9 +433,19 @@ static int builtin_complete(parser_t &parser, wchar_t **argv) break; case 'C': + { do_complete = true; - do_complete_param = w.woptarg ? w.woptarg : reader_get_buffer(); + const wchar_t *arg = w.woptarg ? w.woptarg : reader_get_buffer(); + if (arg == NULL) + { + // This corresponds to using 'complete -C' in non-interactive mode + // See #2361 + builtin_missing_argument(parser, argv[0], argv[w.woptind-1]); + return STATUS_BUILTIN_ERROR; + } + do_complete_param = arg; break; + } case 'h': builtin_print_help(parser, argv[0], stdout_buffer); |