git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: David Kastrup <dak@gnu.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] builtin/blame.c::prepare_lines: fix allocation size of sb->lineno
Date: Sat, 8 Feb 2014 16:21:54 -0500	[thread overview]
Message-ID: <20140208212154.GA4283@sigill.intra.peff.net> (raw)
In-Reply-To: <87lhxmc4sr.fsf@fencepost.gnu.org>

On Sat, Feb 08, 2014 at 10:49:40AM +0100, David Kastrup wrote:

> But please note that since sb->lineno originally comes from a zeroed
> memory area and is passed to xrealloc, this requires that after
> 
> int *p;
> memset(&p, 0, sizeof(p));
> 
> the equivalence
> 
> ((void *)p == NULL)
> 
> will hold.  While this is true on most platforms, and while the C
> standard guarantees the slightly different
> ((void *)0 == NULL)
> is true, it makes no statement concerning the memory representation of
> the NULL pointer.
> 
> I have not bothered addressing this non-compliance with the C standard
> as it would be polishing a turd.  A wholesale replacement has already
> been proposed, and it's likely that this assumption is prevalent in the
> Git codebase elsewhere anyway.

Yes, we explicitly break this part of the standard in the name of
practicality (it simplifies frequently-used code, and machines on which
it matters are rare enough that nobody has ever complained about it).

So I do not think this is a problem.

However, is there a reason not to use:

  sizeof(*sb->lineno)

rather than

  sizeof(int)

to avoid type-mismatch errors entirely (this applies both to this patch,
and to any proposed rewrites using malloc).

-Peff

  reply	other threads:[~2014-02-08 21:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08  9:19 [PATCH] builtin/blame.c::prepare_lines: fix allocation size of sb->lineno David Kastrup
2014-02-08  9:49 ` David Kastrup
2014-02-08 21:21   ` Jeff King [this message]
2014-02-08 21:34     ` David Kastrup

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=20140208212154.GA4283@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=dak@gnu.org \
    --cc=git@vger.kernel.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).