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

Re: [PATCH 0/4] use xmalloc in more places

From
Jeff King <peff@peff.net>
Date
Apr 11, 2019, 19:37 UTC
Message-ID
<20190411193735.GB32528@sigill.intra.peff.net>
In-Reply-To
<20190411191452.GA21290@D-10-18-172-132.dhcp4.washington.edu>
On Thu, Apr 11, 2019 at 12:14:52PM -0700, Taylor Blau wrote:
Show 13 quoted lines
> > This series cleans up most of the bare calls found by:
> >
> >   git grep -E '[^a-z_](m|c|re)alloc\(' '*.c' :^compat :^contrib :^wrapper.c
> 
> This (admittedly pretty awesome) 'git grep' invocation reminds me of a
> series I was pretty sure you wrote to ban functions like 'strcpy' and
> other obviously bad things.
> 
> Some quick searching turned up [1], which landed as f225611d1c
> (automatically ban strcpy(), 2018-07-26). Do we want something similar
> here? Of course, the locations below would have to be exempt, but it
> seems worthwhile (and would save a review cycle in the case that someone
> added a 'malloc' in a patch sent here).
I don't think we can ban malloc, since we have to use it ourselves. :)

With some contortions, we probably could unban it specifically in wrapper.c (though note there are a few other calls I've left which would need to be handled somehow).

Another option would be coccinelle patches to convert malloc() to xmalloc(), etc (with an exception for the wrappers). I'm not entirely comfortable with automatic conversion here because there's often some follow-up adjustments (i.e., we can stop handling allocation errors and maybe delete some code). I think coccinelle can identify callers and barf, though.

I'm not sure whether coccinelle saves review cycles (since that implies people actually run it, though maybe that is better now that it's part of Travis?). It seems to me that it's usually more helpful for people periodically doing follow-up auditing.

So I dunno. If this was a common mistake I'd be more concerned with saving review cycles, but all of the cases I found were actually just leftovers from the very early days of Git.

-Peff
Previous: Taylor BlauNext: Taylor Blau
Message 7 of 9 in “use xmalloc in more places”
  1. 0/4 use xmalloc in more placesJeff King, Apr 11, 2019
  2. 1/4 test-prio-queue: use xmallocJeff King, Apr 11, 2019
  3. 2/4 xdiff: use git-compat-utilJeff King, Apr 11, 2019
  4. 3/4 xdiff: use xmalloc/xreallocJeff King, Apr 11, 2019
  5. 4/4 progress: use xmalloc/xcallocJeff King, Apr 11, 2019
  6. Taylor BlauApr 11, 2019
  7. Jeff KingApr 11, 2019
  8. Taylor BlauApr 11, 2019
  9. Jeff KingApr 11, 2019

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.