From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: sorting
Date: Mon, 22 Jan 2007 17:03:01 +0000 [thread overview]
Message-ID: <20070122170301.6f6a6419.pws@csr.com> (raw)
In-Reply-To: <200701212239.l0LMdbEE015773@pwslaptop.csr.com>
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
prev parent reply other threads:[~2007-01-22 17:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-21 22:39 Peter Stephenson
2007-01-22 17:03 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070122170301.6f6a6419.pws@csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).