about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-01-22 17:28:15 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-01-22 17:28:15 +0000
commite4cc61d5c66556c6aad10a4b7ef169a5d210d17e (patch)
tree26b914e67682bc1a885d3275d20994b31423aa9c /Src
parente375d5ee8817e7f98d0a2f37cfb7566b8572d0e0 (diff)
downloadzsh-e4cc61d5c66556c6aad10a4b7ef169a5d210d17e.tar.gz
zsh-e4cc61d5c66556c6aad10a4b7ef169a5d210d17e.tar.xz
zsh-e4cc61d5c66556c6aad10a4b7ef169a5d210d17e.zip
23122: bug with new sort stuff
Diffstat (limited to 'Src')
-rw-r--r--Src/sort.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Src/sort.c b/Src/sort.c
index 1b8507342..f312150df 100644
--- a/Src/sort.c
+++ b/Src/sort.c
@@ -68,15 +68,23 @@ eltpcmp(const void *a, const void *b)
 	else
 	    len = be->len;
 
-	for (cmpa = as, cmpb = bs; *cmpa == *cmpb && len--; cmpa++, cmpb++)
-	    if (!*cmpa)
+	for (cmpa = as, cmpb = bs; *cmpa == *cmpb && len--; cmpa++, cmpb++) {
+	    if (!*cmpa) {
+		/*
+		 * If either string doesn't have a length, we've reached
+		 * the end.  This is covered in the test below.
+		 */
+		if (ae->len == -1 || be->len == -1)
+		    break;
 		laststarta = cmpa + 1;
+	    }
+	}
 	if (*cmpa == *cmpb && ae->len != be->len) {
 	    /*
 	     * Special case: one of the strings has finished, but
 	     * another one continues after the NULL.  The string
 	     * that's finished sorts below the other.  We need
-	     * to handle this here since stroll() or strcmp()
+	     * to handle this here since strcoll() or strcmp()
 	     * will just compare the strings as equal.
 	     */
 	    if (ae->len != -1) {
@@ -136,7 +144,7 @@ eltpcmp(const void *a, const void *b)
 #ifndef HAVE_STRCOLL
     else
 	cmp = strcmp(as, bs);
-#endif	
+#endif
 
     return sortdir * cmp;
 }
@@ -351,8 +359,7 @@ strmetasort(char **array, int sortwhat, int *unmetalenp)
 	}
     }
     /*
-     * We need to restore sortdir so that calls to
-     * [n]strcmp work when 
+     * We probably don't need to restore the following, but it's pretty cheap.
      */
     oldsortdir = sortdir;
     oldsortnumeric = sortnumeric;