git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [bug report] git-am applying maildir patches in reverse

From
Jeff King <peff@peff.net>
Date
Mar 2, 2013, 00:41 UTC
Message-ID
<20130302004120.GB14936@sigill.intra.peff.net>
In-Reply-To
<7v1ubyek9n.fsf@alter.siamese.dyndns.org>
On Fri, Mar 01, 2013 at 04:08:04PM -0800, Junio C Hamano wrote:
Show 8 quoted lines
> > +static int maildir_filename_cmp(const char *a, const char *b)
> > +{
> > +	while (1) {
> 
> It is somewhat funny that we do not need to check !*a or !*b in this
> loop.  As long as readdir() does not return duplicates, we won't be
> comparing the same strings with this function, and we won't read
> past '\0' at the end of both a and b at the same time.

Ugh, thanks for catching. I had structured this differently at first with a while(1), and then after refactoring it forgot to update the loop condition. Even if it is fine without duplicates, we should not rely on that not to cause an infinite loop (in case the function is ever used again). But moreover, you can trigger the problem even now, since we would parse "foo_0123" and "foo_123" as equivalent, and hit the NUL.

I think this needs squashed in:
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 772c668..1ddbff4 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -132,7 +132,7 @@ static int maildir_filename_cmp(const char *a, const char *b)
 
 static int maildir_filename_cmp(const char *a, const char *b)
 {
-	while (1) {
+	while (*a && *b) {
 		if (isdigit(*a) && isdigit(*b)) {
 			long int na, nb;
 			na = strtol(a, (char **)&a, 10);
@@ -148,6 +148,7 @@ static int maildir_filename_cmp(const char *a, const char *b)
 			b++;
 		}
 	}
+	return *a - *b;
 }
 
 static int split_maildir(const char *maildir, const char *dir,

-Peff
Previous: Junio C HamanoNext: Andreas Schwab
Message 10 of 14 in “[bug report] git-am applying maildir patches in reverse”
  1. William GiokasMar 1, 2013
  2. Junio C HamanoMar 1, 2013
  3. Jeff KingMar 1, 2013
  4. Jeff KingMar 1, 2013
  5. Junio C HamanoMar 1, 2013
  6. Jeff KingMar 1, 2013
  7. Junio C HamanoMar 1, 2013
  8. Jeff KingMar 2, 2013
  9. Junio C HamanoMar 2, 2013
  10. Jeff KingMar 2, 2013
  11. Andreas SchwabMar 2, 2013
  12. Junio C HamanoMar 3, 2013
  13. Jeff KingMar 3, 2013
  14. Jeff KingMar 3, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.