From 77cca4a908ba0b497ced1374b53840eca3f1ca73 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Fri, 23 Nov 2001 19:34:54 +0000 Subject: 16269: Fix crash on reserved-word completion. --- Src/Zle/compctl.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'Src') diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 1094684aa..b4981a842 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -1762,7 +1762,7 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat) struct cmlist ms; Cmlist m; char *os = s; - int onm = nmatches, osi = movefd(0); + int onm = nmatches, odm = diffmatches, osi = movefd(0); LinkNode n; /* We build a copy of the list of matchers to use to make sure that this @@ -1812,8 +1812,13 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat) mnum = 0; unambig_mnum = -1; isuf = NULL; - insmnum = insgnum = 1; - insgroup = oldlist = oldins = 0; + insmnum = 1; +#if 0 + /* group-numbers in compstate[insert] */ + insgnum = 1; + insgroup = 0; +#endif + oldlist = oldins = 0; begcmgroup("default", 0); menucmp = menuacc = newmatches = onlyexpl = 0; @@ -1838,11 +1843,12 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat) if (oldlist) { nmatches = onm; + diffmatches = odm; validlist = 1; amatches = lastmatches; lmatches = lastlmatches; if (pmatches) { - freematches(pmatches); + freematches(pmatches, 1); pmatches = NULL; hasperm = 0; } @@ -1852,7 +1858,7 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat) return 0; } if (lastmatches) { - freematches(lastmatches); + freematches(lastmatches, 1); lastmatches = NULL; } permmatches(1); @@ -2090,7 +2096,7 @@ dumphashtable(HashTable ht, int what) for (i = 0; i < ht->hsize; i++) for (hn = ht->nodes[i]; hn; hn = hn->next) - addmatch(hn->nam, (char *) hn); + addmatch(dupstring(hn->nam), (char *) hn); } /* ScanFunc used by maketildelist() et al. */ @@ -2262,13 +2268,14 @@ static int cdepth = 0; static int makecomplistctl(int flags) { + Heap oldheap; int ret; if (cdepth == MAX_CDEPTH) return 0; cdepth++; - SWITCHHEAPS(compheap) { + SWITCHHEAPS(oldheap, compheap) { int ooffs = offs, lip, lp; char *str = comp_str(&lip, &lp, 0), *t; char *os = cmdstr, **ow = clwords, **p, **q, qc; @@ -2327,7 +2334,7 @@ makecomplistctl(int flags) clwords = ow; clwnum = on; clwpos = op; - } SWITCHBACKHEAPS; + } SWITCHBACKHEAPS(oldheap); cdepth--; return ret; @@ -2463,7 +2470,7 @@ makecomplistcmd(char *os, int incmd, int flags) return ret; } -/* This add the matches for the pattern compctls. */ +/* This adds the matches for the pattern compctls. */ /**/ static int @@ -2471,9 +2478,12 @@ makecomplistpc(char *os, int incmd) { Patcomp pc; Patprog pat; - char *s = findcmd(cmdstr, 1); + char *s; int ret = 0; + s = ((shfunctab->getnode(shfunctab, cmdstr) || + builtintab->getnode(builtintab, cmdstr)) ? NULL : findcmd(cmdstr, 1)); + for (pc = patcomps; pc; pc = pc->next) { if ((pat = patcompile(pc->pat, PAT_STATIC, NULL)) && (pattry(pat, cmdstr) || @@ -2743,7 +2753,7 @@ sep_comp_string(char *ss, char *s, int noffs) LinkNode n; int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs; int sl = strlen(ss), tl, got = 0, i = 0, cur = -1, oll = ll, remq; - int ois = instring, oib = inbackt; + int ois = instring, oib = inbackt, ona = noaliases; char *tmp, *p, *ns, *ol = (char *) line, sav, *oaq = autoq, *qp, *qs; char *ts, qc = '\0'; @@ -2803,7 +2813,7 @@ sep_comp_string(char *ss, char *s, int noffs) } i++; } while (tok != ENDINPUT && tok != LEXERR); - noaliases = 0; + noaliases = ona; strinend(); inpop(); errflag = zleparse = 0; @@ -3638,6 +3648,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) LinkList foo = newlinklist(); LinkNode n; int first = 1, ng = opts[NULLGLOB], oowe = we, oowb = wb; + int ona = noaliases; char *tmpbuf; opts[NULLGLOB] = 1; @@ -3659,7 +3670,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) addlinknode(foo, ztrdup(tokstr)); first = 0; } while (tok != ENDINPUT && tok != LEXERR); - noaliases = 0; + noaliases = ona; strinend(); inpop(); errflag = zleparse = 0; @@ -3682,7 +3693,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) Patprog pprogc = NULL; char *e, *h, hpatsav; int i = addhistnum(curhist,-1,HIST_FOREIGN), n = cc->hnum; - Histent he = quietgethistent(i, GETHIST_UPWARD); + Histent he = gethistent(i, GETHIST_UPWARD); /* Parse the pattern, if it isn't the null string. */ if (*(cc->hpat)) { @@ -3739,7 +3750,10 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) dumphashtable(aliastab, t | (cc->mask & (CC_DISCMDS|CC_EXCMDS))); if (keypm && cc == &cc_dummy) { /* Add the keys of the parameter in keypm. */ - scanhashtable(keypm->gets.hfn(keypm), 0, 0, PM_UNSET, addhnmatch, 0); + HashTable t = keypm->gets.hfn(keypm); + + if (t) + scanhashtable(t, 0, 0, PM_UNSET, addhnmatch, 0); keypm = NULL; cc_dummy.suffix = NULL; } -- cgit 1.4.1