From: Pierre Habouzit <madcoder@debian.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: Use of strbuf.buf when strbuf.len == 0
Date: Thu, 27 Sep 2007 12:13:00 +0200 [thread overview]
Message-ID: <20070927101300.GD10289@artemis.corp> (raw)
In-Reply-To: <7vir5wy6fv.fsf@gitster.siamese.dyndns.org>
[-- Attachment #1: Type: text/plain, Size: 1345 bytes --]
On Thu, Sep 27, 2007 at 06:21:24AM +0000, Junio C Hamano wrote:
> It might be an easier and safer fix to define that strbuf_init()
> to always have allocation. Use of a strbuf in the code _and_
> not adding any contents to the buffer should be an exception and
> avoiding malloc()/free() for that special case feels optimizing
> for the wrong case.
>
> However, there are strbuf instances that are not initialized
> (i.e. in BSS or initialized by declaring with STRBUF_INIT), so
> we still need to handle (.len == 0 && .alloc == 0) case
> specially anyway.
I can see a way, that would need special proof-reading of the strbuf
module, but should not harm its users, that would be to change
STRBUF_INIT to work this way:
{ .buf = "", .len = 0, .alloc = 0 }
It needs to make strbuf_grow and strbuf_release check for ->alloc
before doing anything stupid.
Though we may have some bits of code that rely on .buf being NULL if
nothing happened. I tried to track them down, but some may remain.
If you agree with this change, that would solve most of the issues
with almost no cost, then I'll propose a new patch with this change.
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-09-27 10:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-27 6:21 Use of strbuf.buf when strbuf.len == 0 Junio C Hamano
2007-09-27 10:13 ` Pierre Habouzit [this message]
2007-09-27 10:51 ` [PATCH 1/2] double free in builtin-update-index.c Pierre Habouzit
2007-09-27 10:58 ` [PATCH 2/2] strbuf change: be sure ->buf is never ever NULL Pierre Habouzit
2007-09-29 0:51 ` Use of strbuf.buf when strbuf.len == 0 Linus Torvalds
2007-09-29 7:48 ` Pierre Habouzit
2007-09-27 11:22 ` Pierre Habouzit
2007-09-27 11:33 ` [PATCH 1/1] Make read_patch_file work on a strbuf Pierre Habouzit
2007-09-27 11:33 ` [PROPER PATCH " Pierre Habouzit
2007-09-27 11:37 ` Use of strbuf.buf when strbuf.len == 0 Pierre Habouzit
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=20070927101300.GD10289@artemis.corp \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.