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

Re: PATCH: sorting



Bad handling of embedded nulls where one of the nulls was really the end of
the string.  This depended on what data was off the end of the string, so
caused unpredictable errors.

Index: Src/sort.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/sort.c,v
retrieving revision 1.2
diff -u -r1.2 sort.c
--- Src/sort.c	22 Jan 2007 14:35:13 -0000	1.2
+++ Src/sort.c	22 Jan 2007 17:00:43 -0000
@@ -68,9 +68,17 @@
 	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
@@ -136,7 +144,7 @@
 #ifndef HAVE_STRCOLL
     else
 	cmp = strcmp(as, bs);
-#endif	
+#endif
 
     return sortdir * cmp;
 }
@@ -351,8 +359,7 @@
 	}
     }
     /*
-     * 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;



To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



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