From e4cc61d5c66556c6aad10a4b7ef169a5d210d17e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 22 Jan 2007 17:28:15 +0000 Subject: 23122: bug with new sort stuff --- Src/sort.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'Src/sort.c') 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; -- cgit 1.4.1