Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: fix a bug in nosort deduplication



Introduced in 49915.

Confusion in pointers could mark the wrong entries in some cases. Make
sure asp is incremented to the correct entry by the outer loop's
'asp++', and don't touch sp at all.

In particular, the third added test was missing the 'foo' entry:

Y01completion.ztst: starting.
--- expected
+++ actual
@@ -1,4 +1,3 @@
 line: {tst }{}
-NO:{foo}
 NO:{bar}
 NO:{baz}
Was testing: nosort dedup with three same-string non-duplicates

---

I have no explanation for why I wrote the code like this, but in my defense it is
very confusing. Wait, is that in my defense?

 Src/Zle/compcore.c      |  8 +++++---
 Test/Y01completion.ztst | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 465cfae1ae..b6a8dd2350 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -3287,7 +3287,7 @@ makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp)
 		if ((*ap)->flags & (CMF_NOLIST | CMF_MULT))
 		    nl++;
 	    }
-	/* used -O nosort or -V, don't sort */
+	/* used -o nosort or -V, don't sort */
 	} else {
 	    /* didn't use -1 or -2, so remove all duplicates (efficient) */
 	    if (!(flags & CGF_UNIQALL) && !(flags & CGF_UNIQCON)) {
@@ -3308,12 +3308,14 @@ makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp)
 		    } else if (!ap[0]->disp) {
 			/* Mark those, that would show the same string in the list. */
 			for (dup = 0; bp[0] && !(bp[0])->disp &&
-				 !strcmp((*ap)->str, (bp[0])->str); bp = ++sp) {
+				 !strcmp((*ap)->str, (bp[0])->str); bp = ++asp) {
 			    (bp[0])->flags |= CMF_MULT;
 			    dup = 1;
 			}
-			if (dup)
+			if (dup) {
 			    (*ap)->flags |= CMF_FMULT;
+			    asp--;
+			}
 		    }
 		}
 		if (del) {
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 53d49df374..24b679c256 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -153,6 +153,31 @@ F:regression test workers/51641
 >FI:{file1}
 >FI:{file2}
 
+  comptesteval '_tst() { compadd -V grp -S /a foo bar; compadd -V grp -S /b foo baz }'
+  comptest $'tst \t'
+0:nosort dedup hides same-string non-duplicate matches
+>line: {tst }{}
+>NO:{foo}
+>NO:{bar}
+>NO:{baz}
+
+  comptesteval '_tst() { local disp1=(Foo Bar); compadd -V grp -d disp1 -S /a foo bar; local disp2=(Foo Baz); compadd -V grp -d disp2 -S /b foo baz; }'
+  comptest $'tst \t'
+0:nosort dedup with display strings does not hide same-string non-duplicate matches
+>line: {tst }{}
+>NO:{Foo}
+>NO:{Bar}
+>NO:{Foo}
+>NO:{Baz}
+
+  comptesteval '_tst() { compadd -V grp -S /a foo; compadd -V grp -S /b foo; compadd -V grp -S /c foo; compadd -V grp bar baz }'
+  comptest $'tst \t'
+0:nosort dedup with three same-string non-duplicates
+>line: {tst }{}
+>NO:{foo}
+>NO:{bar}
+>NO:{baz}
+
   # Temporarily modify format set in comptest
   comptesteval 'zstyle -s ":completion:*:descriptions" format oldfmt'
   comptesteval 'zstyle ":completion:*:descriptions" format \
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author