git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Git Mailing list <git@vger.kernel.org>
Cc: "Carlos Martín Nieto" <cmn@elego.de>,
	"Henrik Grubbström" <grubba@roxen.com>
Subject: [PATCH] lf_to_crlf_filter(): tell the caller we added "\n" when draining
Date: Fri, 16 Dec 2011 14:43:20 -0800	[thread overview]
Message-ID: <7vaa6sgmt3.fsf_-_@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7viplggoq9.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Fri, 16 Dec 2011 14:01:50 -0800")

This can only happen when the input size is multiple of the
buffer size of the cascade filter (16k) and ends with an LF,
but in such a case, the code forgot to tell the caller that
it added the "\n" it could not add during the last round.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 convert.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/convert.c b/convert.c
index c2c2c11..c028275 100644
--- a/convert.c
+++ b/convert.c
@@ -879,7 +879,7 @@ int is_null_stream_filter(struct stream_filter *filter)
 
 struct lf_to_crlf_filter {
 	struct stream_filter filter;
-	int want_lf;
+	unsigned want_lf:1;
 };
 
 static int lf_to_crlf_filter_fn(struct stream_filter *filter,
@@ -895,8 +895,11 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
 		lf_to_crlf->want_lf = 0;
 	}
 
-	if (!input)
-		return 0; /* We've already dealt with the state */
+	/* We are told to drain */
+	if (!input) {
+		*osize_p -= o;
+		return 0;
+	}
 
 	count = *isize_p;
 	if (count) {
@@ -931,10 +934,9 @@ static struct stream_filter_vtbl lf_to_crlf_vtbl = {
 
 static struct stream_filter *lf_to_crlf_filter(void)
 {
-	struct lf_to_crlf_filter *lf_to_crlf = xmalloc(sizeof(*lf_to_crlf));
+	struct lf_to_crlf_filter *lf_to_crlf = xcalloc(1, sizeof(*lf_to_crlf));
 
 	lf_to_crlf->filter.vtbl = &lf_to_crlf_vtbl;
-	lf_to_crlf->want_lf = 0;
 	return (struct stream_filter *)lf_to_crlf;
 }
 
-- 
1.7.8.351.g9111b

  reply	other threads:[~2011-12-16 22:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 17:40 Infinite loop in cascade_filter_fn() Henrik Grubbström
2011-11-25 14:31 ` Carlos Martín Nieto
2011-11-25 15:38 ` Carlos Martín Nieto
2011-11-25 16:14   ` Henrik Grubbström
2011-11-25 17:02     ` Carlos Martín Nieto
2011-11-26 22:48       ` Junio C Hamano
2011-11-28 10:48         ` Carlos Martín Nieto
2011-11-28 19:18           ` Junio C Hamano
2011-12-16 22:01           ` Junio C Hamano
2011-12-16 22:43             ` Junio C Hamano [this message]
2011-12-19 10:19               ` [PATCH] lf_to_crlf_filter(): tell the caller we added "\n" when draining Henrik Grubbström
2011-12-19 20:23                 ` Junio C Hamano
2011-12-19 16:42             ` Infinite loop in cascade_filter_fn() Carlos Martín Nieto
2011-11-25 15:43 ` Henrik Grubbström
2011-11-25 15:53   ` Carlos Martín Nieto
2011-11-25 15:59     ` Henrik Grubbström

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vaa6sgmt3.fsf_-_@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=cmn@elego.de \
    --cc=git@vger.kernel.org \
    --cc=grubba@roxen.com \
    /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://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).