From 80a02c10aa85c1b57376faede83cb90a8079c5d7 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 28 Sep 2017 00:58:21 +0200 Subject: 41772: fix bug in handling of long options with _arguments' -A option --- Src/Zle/computil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Src/Zle/computil.c') diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index e704f9ffa..0368a07d0 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1824,7 +1824,7 @@ ca_inactive(Cadef d, char **xor, int cur, int opts) char *x; /* current word could be a prefix of a longer one so only do * exclusions for single-letter options (for option clumping) */ - int single = (cur == compcurrent); + int single = !opts && (cur == compcurrent); for (; (x = (opts ? "-" : *xor)); xor++) { int excludeall = 0; -- cgit v1.2.3 From 12902206b755e05b0b998b521c5998da1f5838cc Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 7 Oct 2017 22:35:59 +0200 Subject: 41824: fix to not complete rest args from an _arguments set alongside the argument to and option in a separate set --- ChangeLog | 4 ++++ Src/Zle/computil.c | 32 ++++++++++++++++---------------- Test/Y03arguments.ztst | 8 ++++++++ 3 files changed, 28 insertions(+), 16 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 168886d5d..916087cb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-10-07 Oliver Kiddle + * 41824: Src/Zle/computil.c, Test/Y03arguments.ztst: fix to + not complete rest args from an _arguments set alongside + the argument to and option in a separate set + * 41823: Completion/Unix/Command/_expand, Completion/Unix/Command/_mv, Completion/Unix/Command/_numfmt, Completion/Unix/Command/_seq, Completion/Unix/Command/_split, diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 0368a07d0..70cea9f27 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1933,7 +1933,6 @@ struct castate { int inopt; /* set to current word pos if word is a recognised option */ int inarg; /* in a normal argument */ int nth; /* number of current normal arg */ - int doff; /* length of current option */ int singles; /* argument consists of clumped options */ int oopt; int actopts; /* count of active options */ @@ -1943,6 +1942,7 @@ struct castate { static struct castate ca_laststate; static int ca_parsed = 0, ca_alloced = 0; +static int ca_doff; /* no. of chars of ignored prefix (for clumped options or arg to an option) */ static void freecastate(Castate s) @@ -2033,7 +2033,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) state.argbeg = state.optbeg = state.nargbeg = state.restbeg = state.actopts = state.nth = state.inopt = state.inarg = state.opt = state.arg = 1; state.argend = argend = arrlen(compwords) - 1; - state.doff = state.singles = state.oopt = 0; + state.singles = state.oopt = 0; state.curpos = compcurrent; state.args = znewlinklist(); state.oargs = (LinkList *) zalloc(d->nopts * sizeof(LinkList)); @@ -2057,7 +2057,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) line; line = compwords[cur++]) { ddef = adef = NULL; dopt = NULL; - doff = state.singles = arglast = 0; + state.singles = arglast = 0; oline = line; #if 0 @@ -2114,7 +2114,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) state.opt = 0; state.argbeg = state.optbeg = state.inopt = cur; state.argend = argend; - doff = state.doff = 0; + doff = 0; state.singles = 1; if (!state.oargs[state.curopt->num]) state.oargs[state.curopt->num] = znewlinklist(); @@ -2287,7 +2287,6 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) memcpy(&ca_laststate, &state, sizeof(state)); ca_laststate.ddef = NULL; ca_laststate.dopt = NULL; - ca_laststate.doff = 0; break; } zaddlinknode(state.args, ztrdup(line)); @@ -2324,7 +2323,6 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) ca_laststate.ddef = NULL; ca_laststate.dopt = NULL; - ca_laststate.doff = 0; break; } } else if (state.def && state.def->end) @@ -2338,7 +2336,6 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) memcpy(&ca_laststate, &state, sizeof(state)); ca_laststate.ddef = NULL; ca_laststate.dopt = NULL; - ca_laststate.doff = 0; } else if (cur == compcurrent && !ca_laststate.def) { if ((ca_laststate.def = ddef)) { ca_laststate.singles = state.singles; @@ -2349,7 +2346,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) ca_laststate.opt = 1; state.curopt->active = 1; } else { - ca_laststate.doff = doff; + ca_doff = doff; ca_laststate.opt = 0; } } else { @@ -2452,11 +2449,16 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc, !strcmp((char *) getdata(anode), arg->action)) break; + /* with an ignored prefix, we're not completing any normal arguments */ + if (single && !arg->opt) + return; + if (!dnode) { addlinknode(descr, arg->descr); addlinknode(act, arg->action); if (!restr) { + if ((restr = (arg->type == CAA_RARGS))) restrict_range(ca_laststate.optbeg, ca_laststate.argend); else if ((restr = (arg->type == CAA_RREST))) @@ -2493,6 +2495,7 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc, if (arg->type == CAA_NORMAL && opt && optdef && optdef->type == CAO_NEXT) return; + if (single) break; @@ -2521,7 +2524,6 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc, if (!single && opt && (lopt || ca_laststate.oopt)) { opt = NULL; arg = ca_get_arg(ca_laststate.d, ca_laststate.nth); - goto rec; } if (!opt && oopt > 0) { @@ -2590,6 +2592,7 @@ bin_comparguments(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) multi = !!def->snext; /* if we have sets */ ca_parsed = cap; + ca_doff = 0; while (def) { /* for each set */ use = !ca_parse_line(def, all, multi, first); @@ -2629,23 +2632,20 @@ bin_comparguments(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) { LinkList descr, act, subc; Caarg arg; - int ign = 0, ret = 1; + int ret = 1; descr = newlinklist(); act = newlinklist(); subc = newlinklist(); + ignore_prefix(ca_doff); while (lstate) { arg = lstate->def; if (arg) { ret = 0; - if (!ign && lstate->doff > 0) { - ign = 1; - ignore_prefix(lstate->doff); - } ca_set_data(descr, act, subc, arg->opt, arg, - lstate->curopt, (lstate->doff > 0)); + lstate->curopt, (ca_doff > 0)); } lstate = lstate->snext; } @@ -2673,7 +2673,7 @@ bin_comparguments(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) for (; lstate; lstate = lstate->snext) { if (lstate->actopts && - (lstate->opt || (lstate->doff && lstate->def) || + (lstate->opt || lstate->def || (lstate->def && lstate->def->opt && (lstate->def->type == CAA_OPT || (lstate->def->type >= CAA_RARGS && diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst index 94ce8361e..de495ee6c 100644 --- a/Test/Y03arguments.ztst +++ b/Test/Y03arguments.ztst @@ -364,6 +364,14 @@ 0:repeatable options >line: {tst -v -v }{} + tst_arguments - set1 '--label=:arg:(a b)' - set2 ':rest:(rest args --label=not)' + comptest $'tst --label=\t' +0:rest arguments from another set not completed after option from first set +>line: {tst --label=}{} +>DESCRIPTION:{arg} +>NO:{a} +>NO:{b} + tst_arguments -A '-*' - help -h -V - other -a '*: :(-x more)' comptest $'tst -a -x m\t' 0:continue completion after rest argument that looks like an option (with sets) -- cgit v1.2.3 From 1bfcff129d27314d2b5b08117a61e67912fafc2d Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 4 Nov 2017 00:57:48 +0100 Subject: 41983: fix exclusion of long options with (-) on a normal argument --- ChangeLog | 5 +++++ Src/Zle/computil.c | 2 +- Test/Y03arguments.ztst | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 4ce3987a2..f27845225 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-11-04 Oliver Kiddle + + * 41983: Src/Zle/computil.c, Test/Y03arguments.ztst: + fix exclusion of long options with (-) on a normal argument + 2017-11-03 Daniel Shahaf * 41969: Completion/Unix/Command/_sort: Clarify option diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 70cea9f27..71d61563b 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2080,7 +2080,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first) remnulargs(line); untokenize(line); - ca_inactive(d, argxor, cur, 0); + ca_inactive(d, argxor, cur - 1, 0); if ((d->flags & CDF_SEP) && cur != compcurrent && !strcmp(line, "--")) { ca_inactive(d, NULL, cur, 1); continue; diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst index de495ee6c..7cbadfe8c 100644 --- a/Test/Y03arguments.ztst +++ b/Test/Y03arguments.ztst @@ -485,12 +485,18 @@ >NO:{-c} >NO:{-g} - tst_arguments '(-)-h' -a -b -c + tst_arguments '(-)-h' -a -b -c --long +p comptest $'tst -h -\t' 0:exclude all other options >line: {tst -h -}{} >MESSAGE:{no arguments} + tst_arguments --args -b -c +p '(-)1:normal' + comptest $'tst arg -\t' +0:exclude all options from a normal argument +>line: {tst arg -}{} +>MESSAGE:{no more arguments} + tst_arguments -a '(-a)-b' comptest $'tst - -b\C-b\C-b\C-b\t' 0:exclusion only applies to later words -- cgit v1.2.3 From 932ed864837b8c43e475784768bd0b00728e756c Mon Sep 17 00:00:00 2001 From: dana Date: Tue, 19 Dec 2017 22:52:29 -0600 Subject: dana: 42145: Fix additional completion cases with option arguments. --- ChangeLog | 5 +++++ Src/Zle/computil.c | 4 +++- Test/Y03arguments.ztst | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index d63c2e513..90fd3f891 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-12-20 Peter Stephenson + + * dana: 42145: Src/Zle/computil.c, Test/Y03arguments.ztst: fix + for completion option arguments. + 2017-12-20 Daniel Shahaf * 42146: Src/hashtable.c, Test/A02alias.ztst: type -w += diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 71d61563b..0b1ba58dc 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2493,7 +2493,9 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc, * the case above right. */ if (arg->type == CAA_NORMAL && - opt && optdef && optdef->type == CAO_NEXT) + opt && optdef && + (optdef->type == CAO_NEXT || optdef->type == CAO_ODIRECT || + optdef->type == CAO_OEQUAL)) return; if (single) diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst index 7cbadfe8c..761b4b1d2 100644 --- a/Test/Y03arguments.ztst +++ b/Test/Y03arguments.ztst @@ -237,6 +237,27 @@ >NO:{-a} >NO:{-b} + tst_arguments '*'{-x+,--xxx=}':optarg:(1)' '*:operand:(a)' + comptest $'tst \t' + comptest $'tst -x \t' + comptest $'tst -x\t' + comptest $'tst --xxx=\t' + comptest $'tst --xxx \t' + comptest $'tst a -x\t' + comptest $'tst a -x \t' + comptest $'tst a --xxx=\t' + comptest $'tst a --xxx \t' +0:optarg completion following rest operand on line (workers/42141) +>line: {tst a }{} +>line: {tst -x 1 }{} +>line: {tst -x1 }{} +>line: {tst --xxx=1 }{} +>line: {tst --xxx 1 }{} +>line: {tst a -x1 }{} +>line: {tst a -x 1 }{} +>line: {tst a --xxx=1 }{} +>line: {tst a --xxx 1 }{} + tst_arguments '-a' '*::rest:{compadd - -b}' comptest $'tst arg -\t' 0:rest arguments -- cgit v1.2.3 From e4a8069b329cacd6486f831bb55273f8253295b2 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Sat, 24 Mar 2018 15:17:37 +0900 Subject: 42501: avoid out of bound pointer (as 42487) --- ChangeLog | 5 +++++ Src/Zle/complete.c | 6 ++---- Src/Zle/computil.c | 4 ++-- Src/Zle/zle_thingy.c | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'Src/Zle/computil.c') diff --git a/ChangeLog b/ChangeLog index 77e2182c5..f17ed6dff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-03-24 Jun-ichi Takimoto + + * 42501: Src/Zle/complete.c, Src/Zle/computil.c, + Src/Zle/zle_thingy.c: avoid out of bound pointer (as 42487). + 2018-03-23 Oliver Kiddle * 42491 based on 42000 (Andrei Shevchuk): diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 16f48c958..313dcb92f 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -715,11 +715,10 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) case 'E': if (p[1]) { dat.dummies = atoi(p + 1); - p = "" - 1; + p += strlen(p+1); } else if (argv[1]) { argv++; dat.dummies = atoi(*argv); - p = "" - 1; } else { zwarnnam(name, "number expected after -%c", *p); zsfree(mstr); @@ -744,13 +743,12 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) /* Pasted argument: -Xfoo. */ if (!*sp) *sp = p + 1; - p = "" - 1; + p += strlen(p+1); } else if (argv[1]) { /* Argument in a separate word: -X foo. */ argv++; if (!*sp) *sp = *argv; - p = "" - 1; } else { /* Missing argument: argv[N] == "-X", argv[N+1] == NULL. */ zwarnnam(name, e, *p); diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 0b1ba58dc..4ce8eeee5 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -1222,7 +1222,7 @@ parse_cadef(char *nam, char **args) else if (*p == 'A') { if (p[1]) { nonarg = p + 1; - p = "" - 1; + p += strlen(p+1); } else if (args[1]) nonarg = *++args; else @@ -1230,7 +1230,7 @@ parse_cadef(char *nam, char **args) } else if (*p == 'M') { if (p[1]) { match = p + 1; - p = "" - 1; + p += strlen(p+1); } else if (args[1]) match = *++args; else diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index f7e9829c2..5601c1178 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -731,6 +731,7 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) break; } while (*++(*args)) { + char skip_this_arg[2] = "x"; switch (**args) { case 'n': num = args[0][1] ? args[0]+1 : args[1]; @@ -741,7 +742,7 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) return 1; } if (!args[0][1]) - *++args = "" - 1; + *++args = skip_this_arg; saveflag = 1; zmod.mult = atoi(num); zmod.flags |= MOD_MULT; @@ -760,7 +761,7 @@ bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) return 1; } if (!args[0][1]) - *++args = "" - 1; + *++args = skip_this_arg; keymap_restore = dupstring(curkeymapname); if (selectkeymap(keymap_tmp, 0)) { if (remetafy) -- cgit v1.2.3