git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Brandon Casey <brandon.casey.ctr@nrlssc.navy.mil>
Cc: Junio C Hamano <gitster@pobox.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Git Mailing List <git@vger.kernel.org>,
	Sverre Rabbelier <srabbelier@gmail.com>
Subject: Re: [PATCH v2] Let mailsplit and mailinfo handle mails with CRLF  line-endings
Date: Tue, 4 Aug 2009 23:58:13 +0200	[thread overview]
Message-ID: <81b0412b0908041458w7e76854bn96c4cb71a5e91e74@mail.gmail.com> (raw)
In-Reply-To: <H9KDJzU0XgndJHC8J4OETn7kxYhGP3gl0YJPR0low0hfIHjZOUsoxw@cipher.nrlssc.navy.mil>

On Tue, Aug 4, 2009 at 23:29, Brandon
Casey<brandon.casey.ctr@nrlssc.navy.mil> wrote:
> Alex Riesen wrote:
>> +     if (c == '\n' && len > 1 && buf[len - 2] == '\r')
>> +             buf[--len - 1] = '\n';
>>       buf[len] = '\0';
>>
>>       return len;
>
> What if \r lands at character 99 and \n is at character 100?  If buf has
> exactly 100 characters available for writing. ...

Ah, yes. You're right.

I have strong dislike towards unget, though. How about this, instead:

int read_line_with_nul(char *buf, int size, FILE *in)
{
	int len = 0, c;

	while (len < size) {
		c = getc(in);
		if (c == EOF)
			break;
		buf[len++] = c;
		if (c == '\n')
			break;
		else if (len == size)
			c = 0;
	}
	if (c == '\n' && len > 1 && buf[len - 2] == '\r')
		buf[--len - 1] = '\n';
	buf[len] = '\0';

	return len;
}

  parent reply	other threads:[~2009-08-04 21:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-03 19:08 Please make git-am handle \r\n-damaged patches H. Peter Anvin
2009-08-03 21:30 ` Junio C Hamano
2009-08-03 21:56   ` Wesley J. Landaker
2009-08-03 22:56     ` H. Peter Anvin
2009-08-03 22:13   ` H. Peter Anvin
2009-08-03 22:21     ` Sverre Rabbelier
2009-08-03 22:31       ` H. Peter Anvin
2009-08-04  6:21       ` Paolo Bonzini
2009-08-04  6:35 ` Alex Riesen
2009-08-04  6:46   ` Junio C Hamano
2009-08-04 17:26     ` [PATCH] Let mailsplit and mailinfo handle mails with CRLF line-endings Alex Riesen
2009-08-04 17:34       ` Sverre Rabbelier
2009-08-04 18:50         ` Brandon Casey
2009-08-04 20:57         ` Alex Riesen
2009-08-04 21:03       ` [PATCH v2] " Alex Riesen
2009-08-04 21:29         ` Brandon Casey
2009-08-04 21:40           ` Brandon Casey
2009-08-04 21:58           ` Alex Riesen [this message]
2009-08-04 22:03             ` Alex Riesen
2009-08-04 22:04               ` Alex Riesen
2009-08-04 22:23             ` Brandon Casey
2009-08-04 20:59     ` Please make git-am handle \r\n-damaged patches Erik Faye-Lund
2009-08-04 21:05       ` Alex Riesen
2009-08-04 21:16         ` Erik Faye-Lund
2009-08-05 23:10       ` Tony Finch
2009-08-04 21:15     ` Nanako Shiraishi
2009-08-04 22:22       ` Junio C Hamano
2009-08-05  3:31         ` [PATCH 0/4] " Brandon Casey
2009-08-05  3:31           ` [PATCH 1/4] strbuf: add new function strbuf_getwholeline() Brandon Casey
2009-08-05  3:31             ` [PATCH 2/4] builtin-mailinfo,builtin-mailsplit: use strbufs Brandon Casey
2009-08-05  3:31               ` [PATCH 3/4] builtin-mailsplit.c: remove read_line_with_nul() since it is no longer used Brandon Casey
2009-08-05  3:31                 ` [PATCH 4/4] Allow mailsplit (and hence git-am) to handle mails with CRLF line-endings Brandon Casey
2009-08-05  5:49                   ` Alex Riesen

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=81b0412b0908041458w7e76854bn96c4cb71a5e91e74@mail.gmail.com \
    --to=raa.lkml@gmail.com \
    --cc=brandon.casey.ctr@nrlssc.navy.mil \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hpa@zytor.com \
    --cc=srabbelier@gmail.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.
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).