list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <>
To: Junio C Hamano <>
Cc: Jeff King <>, Derrick Stolee <>,
Subject: Re: [PATCH] xrealloc: do not reuse pointer freed by zero-length realloc()
Date: Wed, 2 Sep 2020 20:50:08 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

Junio C Hamano wrote:
> Jeff King <> writes:

>> If we do handle it up-front, then I think we'd actually want:
>>   if (!size) {
>>           free(ptr);
>>           return xmalloc(0);
>>   }
>> (i.e., to never return NULL for consistency with xmalloc() and
>> xcalloc()).
> Makes sense.  I suspect that this is optimizing for a wrong case,
> but in practice that should not matter.  Not having to worry about
> a request to resize to 0-byte in the remainder of the function is
> actually a plus for readability, I would say.

I agree with both points: if we were repeatedly shrinking and growing
a buffer and cared about its performance, then we'd want the first
version, and since we aren't, we should prefer this version that is
more readable.


  parent reply	other threads:[~2020-09-03  3:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01 11:18 Jeff King
2020-09-01 13:04 ` Derrick Stolee
2020-09-01 13:51   ` Jeff King
2020-09-01 14:24     ` Derrick Stolee
2020-09-01 15:58     ` Junio C Hamano
2020-09-02  7:54       ` Jeff King
2020-09-02 19:19         ` Junio C Hamano
2020-09-03  3:50       ` Jonathan Nieder [this message]
2020-09-01 15:20 ` Andreas Schwab
2020-09-01 15:56 ` 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:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \
    --subject='Re: [PATCH] xrealloc: do not reuse pointer freed by zero-length realloc()' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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).