git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtin/blame.c::prepare_lines: fix allocation size of sb->lineno

From
Jeff King <peff@peff.net>
Date
Feb 8, 2014, 21:21 UTC
Message-ID
<20140208212154.GA4283@sigill.intra.peff.net>
In-Reply-To
<87lhxmc4sr.fsf@fencepost.gnu.org>
On Sat, Feb 08, 2014 at 10:49:40AM +0100, David Kastrup wrote:
Show 20 quoted lines
> 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
Previous: David KastrupNext: David Kastrup
Message 3 of 4 in “builtin/blame.c::prepare_lines: fix allocation size of sb->lineno”
  1. builtin/blame.c::prepare_lines: fix allocation size of sb->linenoDavid Kastrup, Feb 8, 2014
  2. David KastrupFeb 8, 2014
  3. Jeff KingFeb 8, 2014
  4. David KastrupFeb 8, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.