From: Jeff King <peff@peff.net>
To: Mike Hommey <mh@glandium.org>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH] fast-import: Reinitialize command_buf rather than detach it.
Date: Sun, 25 Aug 2019 03:28:10 -0400 [thread overview]
Message-ID: <20190825072809.GD23806@sigill.intra.peff.net> (raw)
In-Reply-To: <20190825072031.2m2go6ssshww6tup@glandium.org>
On Sun, Aug 25, 2019 at 04:20:31PM +0900, Mike Hommey wrote:
> > I think this is stronger than just "most of the time". It's an invariant
> > for strbufs to have a NUL, so the only case where detaching isn't a noop
> > is the empty slopbuf case you mention.
>
> If it's an invariant, why does detach actively tries to realloc and set
> the nul terminator as if it can happen in more cases than when using the
> slopbuf?
It calls strbuf_grow() to handle the slopbuf case (we can't hand off the
slopbuf, since the caller expects an allocated buffer). It just doesn't
bother to distinguish that case itself, and lets strbuf_grow() handle
it.
I think it would be equally correct for strbuf_detach() to do:
if (!sb->alloc)
strbuf_grow(0);
> > Splitting hairs, perhaps, but I think with that explanation, we could
> > probably argue that this case will never come up: strbuf_getline will
> > either have allocated a buffer or will have returned EOF.
>
> Note that the slopbuf case _does_ come up, and we always leak a 1 byte
> buffer.
Hmm, I suppose so, on the very first call before we've read anything
(and likewise if parse_data() reset it then got an EOF, and we then
tried to read another command).
> I do agree the way fast-import works between cmd_hist and command_buf is
> very brittle, as you've shown. I didn't feel like digging into it
> though. Thanks for having gone further than I did.
I'll see if I can shape my rambling into a patch.
-Peff
next prev parent reply other threads:[~2019-08-25 7:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-25 4:13 [PATCH] fast-import: Reinitialize command_buf rather than detach it Mike Hommey
2019-08-25 6:57 ` Jeff King
2019-08-25 7:20 ` Mike Hommey
2019-08-25 7:28 ` Jeff King [this message]
2019-08-25 8:06 ` [PATCH 0/2] fast-import input string handling bugs Jeff King
2019-08-25 8:08 ` [PATCH 1/2] fast-import: duplicate parsed encoding string Jeff King
2019-08-26 18:28 ` Elijah Newren
2019-08-26 18:44 ` Jeff King
2019-08-25 8:10 ` [PATCH 2/2] fast-import: duplicate into history rather than passing ownership Jeff King
2019-08-25 10:02 ` Mike Hommey
2019-08-25 14:21 ` René Scharfe
2019-08-26 18:42 ` Jeff King
2019-08-26 15:36 ` [PATCH 0/2] fast-import input string handling bugs Junio C Hamano
2019-08-26 19:18 ` Elijah Newren
2019-08-25 12:35 ` [PATCH] fast-import: Reinitialize command_buf rather than detach it René Scharfe
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=20190825072809.GD23806@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mh@glandium.org \
/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).