From: Taylor Blau <me@ttaylorr.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 02/10] unpack_loose_header(): simplify next_out assignment
Date: Thu, 27 Feb 2025 19:18:49 -0500 [thread overview]
Message-ID: <Z8EA6SGpwiV5pv7J@nand.local> (raw)
In-Reply-To: <20250225062900.GB1293961@coredump.intra.peff.net>
On Tue, Feb 25, 2025 at 01:29:00AM -0500, Jeff King wrote:
> When using OBJECT_INFO_ALLOW_UNKNOWN_TYPE to unpack a header that
> doesn't fit into our initial 32-byte buffer, we loop over calls
> git_inflate(), feeding it our buffer to the "next_out" pointer each
> time. As the code is written, we reset next_out after each inflate call
> (and after reading the output), ready for the next loop.
>
> This isn't wrong, but there are a few advantages to setting up
> "next_out" right before each inflate call, rather than after:
>
> 1. It drops a few duplicated lines of code.
>
> 2. It makes it obvious that we always feed a fresh buffer on each call
> (and thus can never see Z_BUF_ERROR due to due to a lack of output
> space).
>
> 3. After we exit the loop, we'll leave stream->next_out pointing to
> the end of the fetched data (this is how zlib callers find out how
> much data is in the buffer). This doesn't matter in practice, since
> nobody looks at it again. But it's probably the least-surprising
> thing to do, as it matches how next_out is left when the whole
> thing fits in the initial 32-byte buffer (and we don't enter the
> loop at all).
Thanks for calling (3) out. There is definitely a subtle behavior change
there, but having the context that it doesn't matter in practice is
useful in judging whether or not the refactoring is OK.
In any event, I agree that this is a much cleaner read, and recall
thinking something along the same lines as (1) when we were working on
this together.
Thanks,
Taylor
next prev parent reply other threads:[~2025-02-28 0:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 6:25 [PATCH 0/10] some zlib inflating bug fixes Jeff King
2025-02-25 6:28 ` [PATCH 01/10] loose_object_info(): BUG() on inflating content with unknown type Jeff King
2025-02-25 11:42 ` Patrick Steinhardt
2025-02-26 1:47 ` Junio C Hamano
2025-02-28 0:16 ` Taylor Blau
2025-03-04 6:43 ` Jeff King
2025-03-04 15:41 ` Junio C Hamano
2025-02-28 0:14 ` Taylor Blau
2025-02-25 6:29 ` [PATCH 02/10] unpack_loose_header(): simplify next_out assignment Jeff King
2025-02-28 0:18 ` Taylor Blau [this message]
2025-02-25 6:29 ` [PATCH 03/10] unpack_loose_header(): report headers without NUL as "bad" Jeff King
2025-02-25 6:29 ` [PATCH 04/10] unpack_loose_header(): fix infinite loop on broken zlib input Jeff King
2025-02-25 11:42 ` Patrick Steinhardt
2025-02-25 19:00 ` Eric Sunshine
2025-02-26 12:56 ` Junio C Hamano
2025-02-28 0:21 ` Taylor Blau
2025-02-25 6:30 ` [PATCH 05/10] git_inflate(): skip zlib_post_call() sanity check on Z_NEED_DICT Jeff King
2025-02-26 13:26 ` Junio C Hamano
2025-02-28 0:31 ` Taylor Blau
2025-03-04 7:08 ` Jeff King
2025-02-25 6:30 ` [PATCH 06/10] unpack_loose_header(): avoid numeric comparison of zlib status Jeff King
2025-02-28 0:32 ` Taylor Blau
2025-03-04 6:55 ` Jeff King
2025-02-25 6:31 ` [PATCH 07/10] unpack_loose_rest(): " Jeff King
2025-02-25 6:33 ` [PATCH 08/10] unpack_loose_rest(): never clean up zstream Jeff King
2025-02-26 13:16 ` Junio C Hamano
2025-02-25 6:33 ` [PATCH 09/10] unpack_loose_rest(): simplify error handling Jeff King
2025-02-26 13:46 ` Junio C Hamano
2025-02-28 0:34 ` Taylor Blau
2025-02-25 6:34 ` [PATCH 10/10] unpack_loose_rest(): rewrite return handling for clarity Jeff King
2025-02-28 0:36 ` Taylor Blau
2025-03-04 7:10 ` Jeff King
2025-03-04 21:32 ` Taylor Blau
2025-02-28 0:38 ` [PATCH 0/10] some zlib inflating bug fixes Taylor Blau
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=Z8EA6SGpwiV5pv7J@nand.local \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.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.
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).