git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH v2 00/21] object_id part 7
Date: Tue, 28 Mar 2017 13:42:14 -0400	[thread overview]
Message-ID: <20170328174214.t5szqndtf4bwsnhz@sigill.intra.peff.net> (raw)
In-Reply-To: <20170328173536.ylwesrj7jbreztcy@sigill.intra.peff.net>

On Tue, Mar 28, 2017 at 01:35:36PM -0400, Jeff King wrote:

> I thought I'd knock this out quickly before I forgot about it. But it
> actually isn't so simple.
> 
> The main caller in read_head_info() does indeed just pass strlen(line)
> as the length in each case. But the cert parser really does need us to
> respect the line length. So we either have to pass it in, or tie off the
> string.
> 
> The latter looks something like the patch below (on top of a minor
> tweak around "eol" handling). It's sufficiently ugly that it may not
> count as an actual cleanup, though. I'm OK if we just drop the idea.

Here's that minor tweak, in case anybody is interested. It's less useful
without that follow-on that touches "eol" more, but perhaps it increases
readability on its own.

-- >8 --
Subject: [PATCH] receive-pack: simplify eol handling in cert parsing

The queue_commands_from_cert() function wants to handle each
line of the cert individually. It looks for "\n" in the
to-be-parsed bytes, and special-cases each use of eol (the
end-of-line variable) when we didn't find one.  Instead, we
can just set the end-of-line variable to end-of-cert in the
latter case.

For advancing to the next line, it's OK for us to move our
pointer past end-of-cert, because our loop condition just
checks for pointer inequality. And it doesn't even violate
the ANSI C "no more than one past the end of an array" rule,
because we know in the worst case we've hit the terminating
NUL of the strbuf.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/receive-pack.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 5d9e4da0a..58de2a1a9 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1524,8 +1524,10 @@ static void queue_commands_from_cert(struct command **tail,
 
 	while (boc < eoc) {
 		const char *eol = memchr(boc, '\n', eoc - boc);
-		tail = queue_command(tail, boc, eol ? eol - boc : eoc - boc);
-		boc = eol ? eol + 1 : eoc;
+		if (!eol)
+			eol = eoc;
+		tail = queue_command(tail, boc, eol - boc);
+		boc = eol + 1;
 	}
 }
 
-- 
2.12.2.845.g55fcf8b10


  reply	other threads:[~2017-03-28 17:42 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-26 16:01 [PATCH v2 00/21] object_id part 7 brian m. carlson
2017-03-26 16:01 ` [PATCH v2 01/21] Define new hash-size constants for allocating memory brian m. carlson
2017-03-26 16:01 ` [PATCH v2 02/21] Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ brian m. carlson
2017-03-26 16:01 ` [PATCH v2 03/21] Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ brian m. carlson
2017-03-26 16:01 ` [PATCH v2 04/21] builtin/diff: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 05/21] builtin/pull: convert portions " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 06/21] builtin/receive-pack: fix incorrect pointer arithmetic brian m. carlson
2017-03-28  6:51   ` Jeff King
2017-03-28 16:58     ` Junio C Hamano
2017-03-26 16:01 ` [PATCH v2 07/21] builtin/receive-pack: convert portions to struct object_id brian m. carlson
2017-03-28  7:07   ` Jeff King
2017-03-29 23:21     ` brian m. carlson
2017-03-30  1:37       ` Jeff King
2017-03-26 16:01 ` [PATCH v2 08/21] fsck: convert init_skiplist " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 09/21] parse-options-cb: convert sha1_array_append caller " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 10/21] test-sha1-array: convert most code " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 11/21] sha1_name: convert struct disambiguate_state to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 12/21] sha1_name: convert disambiguate_hint_fn to take object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 13/21] submodule: convert check_for_new_submodule_commits to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 14/21] builtin/pull: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 15/21] sha1-array: convert internal storage for struct sha1_array to object_id brian m. carlson
2017-03-28  7:24   ` Jeff King
2017-03-26 16:01 ` [PATCH v2 16/21] Make sha1_array_append take a struct object_id * brian m. carlson
2017-03-28  7:26   ` Jeff King
2017-03-28 17:27   ` Junio C Hamano
2017-03-29  0:06     ` brian m. carlson
2017-03-29 15:14       ` Junio C Hamano
2017-03-29 22:28         ` brian m. carlson
2017-03-26 16:01 ` [PATCH v2 17/21] Convert remaining callers of sha1_array_lookup to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 18/21] Convert sha1_array_lookup to take struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 19/21] Convert sha1_array_for_each_unique and for_each_abbrev to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 20/21] Rename sha1_array to oid_array brian m. carlson
2017-03-26 16:01 ` [PATCH v2 21/21] Documentation: update and rename api-sha1-array.txt brian m. carlson
2017-03-28  7:31 ` [PATCH v2 00/21] object_id part 7 Jeff King
2017-03-28 11:13   ` brian m. carlson
2017-03-28 17:35     ` Jeff King
2017-03-28 17:42       ` Jeff King [this message]
2017-03-28 19:40         ` Junio C Hamano
2017-03-28 20:00           ` Jeff King
2017-03-28 17:32   ` Junio C Hamano

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=20170328174214.t5szqndtf4bwsnhz@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /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).