From: "René Scharfe" <l.s.r@web.de>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>, David Kastrup <dak@gnu.org>
Subject: Re: [PATCH 2/2] blame: simplify prepare_lines()
Date: Fri, 13 Jun 2014 23:33:37 +0200 [thread overview]
Message-ID: <539B6E31.1080901@web.de> (raw)
In-Reply-To: <20140613211339.GL8557@google.com>
Am 13.06.2014 23:13, schrieb Jonathan Nieder:
> René Scharfe wrote:
>
>> - if (incomplete)
>> - *lineno++ = len;
>> + *lineno = len;
>>
>> - sb->num_lines = num + incomplete;
>> + sb->num_lines = num;
>
> This will always treat whatever comes after the last newline as an
> incomplete line, even if it has zero length. Is that safe? (Not a
> rhetorical question --- I haven't looked carefully at the caller.)
There is no need to look at the caller -- the contents of the lineno
array is not (intended to be) changed by the patch.
The original code is:
p = memchr(p, '\n', end - p);
if (p) {
p++;
*lineno++ = p - buf;
continue;
}
Suppose there is no incomplete line. For the last EOL of a buffer, p
points to buf[len - 1] after the memchr call. Then it is incremented.
Then buf + len - buf is written into the last lineno member -- same as
after the patch.
Makes sense?
René
next prev parent reply other threads:[~2014-06-13 21:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-13 19:53 [PATCH 1/2] blame: factor out get_next_line() René Scharfe
2014-06-13 19:54 ` [PATCH 2/2] blame: simplify prepare_lines() René Scharfe
2014-06-13 21:13 ` Jonathan Nieder
2014-06-13 21:33 ` René Scharfe [this message]
2014-06-13 21:46 ` Jonathan Nieder
2014-06-13 21:05 ` [PATCH 1/2] blame: factor out get_next_line() Jonathan Nieder
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=539B6E31.1080901@web.de \
--to=l.s.r@web.de \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@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).