summaryrefslogtreecommitdiff
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
parente375d5ee8817e7f98d0a2f37cfb7566b8572d0e0 (diff)
downloadzsh-e4cc61d5c66556c6aad10a4b7ef169a5d210d17e.tar.gz
zsh-e4cc61d5c66556c6aad10a4b7ef169a5d210d17e.zip
23122: bug with new sort stuff
-rw-r--r--ChangeLog5
-rw-r--r--Src/sort.c19
2 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a747e8aa2..d1e7aa713 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2007-01-22 Peter Stephenson <pws@csr.com>
+ * 23122: Src/sort.c: bug with some strings with embedded nulls and
+ some not in 23118.
+
+2007-01-22 Peter Stephenson <pws@csr.com>
+
* 23119: Src/sort.c, Test/B03print.ztst, Test/D07multibyte.ztst:
do lowering of multibyte character case in sorting properly.
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;