From eeeba19c965f29f9be1d1181222f2d3ef428da2b Mon Sep 17 00:00:00 2001 From: dana Date: Thu, 28 Dec 2017 01:47:57 -0600 Subject: 42185: safety when removing separators in completion --- Src/Zle/compcore.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Src/Zle/compcore.c') diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 52b0c173f..c3b971e0d 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1901,7 +1901,8 @@ set_comp_sep(void) p = compwords[i] = (char *) getdata(n); untokenize(p); } - compcurrent = cur + 1; + /* The current position shouldn't exceed the new word count */ + compcurrent = cur + 1 > i ? i : cur + 1; compwords[i] = NULL; } instring = ois; -- cgit v1.2.3 From e5f356a95e3c867e1f554e1b77dd6b463566107a Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Fri, 25 May 2018 20:36:37 +0900 Subject: 42809: slightly improve 'compset -q' --- ChangeLog | 4 ++++ Src/Zle/compcore.c | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index dda1c6b22..3f7e95417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-05-25 Jun-ichi Takimoto + + * 42809: Src/Zle/compcore.c: slightly improve 'compset -q' + 2018-05-19 Oliver Kiddle * 42806: Completion/Unix/Command/_shutdown: fix where options diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index c3b971e0d..f733e0ee5 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1638,7 +1638,7 @@ set_comp_sep(void) p[-1] = '\0'; } } - if (tok == ENDINPUT || tok == LEXERR) + if (tok == ENDINPUT) break; if (tokstr && *tokstr) { for (p = tokstr; dq && *p; p++) { @@ -1667,7 +1667,7 @@ set_comp_sep(void) if (!got && !lexflags) { DPUTS(!p, "no current word in substr"); got = 1; - cur = i; + cur = countlinknodes(foo) - 1; /* cur is 0 offset */ swb = wb - 1 - dq - sq - dolq; swe = we - 1 - dq - sq - dolq; sqq = lsq; @@ -1902,7 +1902,10 @@ set_comp_sep(void) untokenize(p); } /* The current position shouldn't exceed the new word count */ - compcurrent = cur + 1 > i ? i : cur + 1; + if ((compcurrent = cur + 1) > i) { + DPUTS2(1, "compcurrent=%d > number_of_words=%d", compcurrent, i); + compcurrent = i; + } compwords[i] = NULL; } instring = ois; -- cgit v1.2.3 From 1a97dcbed1bf0b8f5225819096670df6a40e9844 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Thu, 31 May 2018 21:07:53 +0900 Subject: 42870: another improvement of 'compset -q' zlemetall need not count the 'x' added at the cursor in set_comp_sep() --- ChangeLog | 4 ++++ Src/Zle/compcore.c | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index c97ad7415..d267e0d18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-05-31 Jun-ichi Takimoto + + * 42870: Src/Zle/compcore.c: another improvement of 'compset -q' + 2018-05-29 Peter Stephenson * c.f. 42865: config.guess, config.sub: update from GNU diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index f733e0ee5..fd415da89 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1610,9 +1610,11 @@ set_comp_sep(void) inpush(dupstrspace(tmp), 0, NULL); zlemetaline = tmp; /* - * Length of temporary string, calculated above. + * tl is the length of temporary string, calculated above. + * It seems zlemetall need not include the 'x' added at the cursor. + * addedx is taken care of in function gotword() (lex.c). */ - zlemetall = tl; + zlemetall = tl - addedx; strinbeg(0); noaliases = 1; do { @@ -1668,8 +1670,8 @@ set_comp_sep(void) DPUTS(!p, "no current word in substr"); got = 1; cur = countlinknodes(foo) - 1; /* cur is 0 offset */ - swb = wb - 1 - dq - sq - dolq; - swe = we - 1 - dq - sq - dolq; + swb = wb - dq - sq - dolq; + swe = we - dq - sq - dolq; sqq = lsq; soffs = zlemetacs - swb - css; DPUTS2(p[soffs] != 'x', "expecting 'x' at offset %d of \"%s\"", -- cgit v1.2.3 From baedd62f0d601bf03d99b2366a8ace42268e88ed Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Tue, 31 Jul 2018 22:15:58 +0900 Subject: 43219 (except term{cap,info}.c): fix several memory leaks --- ChangeLog | 6 ++++++ Src/Modules/db_gdbm.c | 5 ++++- Src/Modules/pcre.c | 1 + Src/Zle/compcore.c | 2 ++ Src/init.c | 3 ++- Src/math.c | 2 +- Src/subst.c | 2 +- 7 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 465320208..e8acff0eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-07-31 Jun-ichi Takimoto + + * 43219 (except term{cap,info}.c): Src/Modules/db_gdbm.c, + Src/Modules/pcre.c, Src/Zle/compcore.c, Src/init.c, Src/math.c, + Src/subst.c: fix several memory leaks + 2018-07-30 Peter Stephenson * 43225: Src/Zle/zle_main.c: recalculate timeout after calling diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c index 5f776f407..ed702b912 100644 --- a/Src/Modules/db_gdbm.c +++ b/Src/Modules/db_gdbm.c @@ -359,7 +359,7 @@ gdbmsetfn(Param pm, char *val) } if (val) { - pm->u.str = ztrdup(val); + pm->u.str = val; pm->node.flags |= PM_UPTODATE; } @@ -732,6 +732,9 @@ static int remove_tied_name( const char *name ) { p++; } + if (*p) + zsfree(*p); + /* Copy x+1 to x */ while (*p) { *p=*(p+1); diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c index 15ee34bc8..6289e003e 100644 --- a/Src/Modules/pcre.c +++ b/Src/Modules/pcre.c @@ -380,6 +380,7 @@ bin_pcre_match(char *nam, char **args, Options ops, UNUSED(int func)) if (ovec) zfree(ovec, ovecsize*sizeof(int)); + zsfree(plaintext); return return_value; } diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index fd415da89..8eca39447 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -3556,6 +3556,8 @@ freematches(Cmgroup g, int cm) } free(g->expls); } + if (g->widths) + free(g->widths); zsfree(g->name); free(g); diff --git a/Src/init.c b/Src/init.c index c5372665a..e9e6be9b4 100644 --- a/Src/init.c +++ b/Src/init.c @@ -459,7 +459,8 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp, /* -c command */ *cmdp = *argv; new_opts[INTERACTIVE] &= 1; - scriptname = scriptfilename = ztrdup("zsh"); + if (toplevel) + scriptname = scriptfilename = ztrdup("zsh"); } else if (**argv == 'o') { if (!*++*argv) argv++; diff --git a/Src/math.c b/Src/math.c index 32bccc6e9..4b7ecf0ab 100644 --- a/Src/math.c +++ b/Src/math.c @@ -535,7 +535,7 @@ lexconstant(void) for (ptr2 = ptr; ptr2 < nptr; ptr2++) { if (*ptr2 == '_') { int len = nptr - ptr; - ptr = ztrdup(ptr); + ptr = dupstring(ptr); for (ptr2 = ptr; len; len--) { if (*ptr2 == '_') chuck(ptr2); diff --git a/Src/subst.c b/Src/subst.c index a265a187e..c1021fbf3 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3169,7 +3169,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, zip = hmkarray(sval); } if (!isarr) { - aval = mkarray(val); + aval = hmkarray(val); isarr = 1; } if (zip) { -- cgit v1.2.3