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

Re: [PATCH] factorize pack structure allocation

From
Jon Loeliger <jdl@freescale.com>
Date
Jun 24, 2008, 23:13 UTC
Message-ID
<48617F7E.4020706@freescale.com>
In-Reply-To
<alpine.LFD.1.10.0806241851420.2979@xanadu.home>
Nicolas Pitre wrote:
Show 24 quoted lines
> New pack structures are currently allocated in 2 different places
> and all members have to be initialized explicitly.  This is prone
> to errors leading to segmentation faults as found by Teemu Likonen.
> 
> Let's have a common place where this structure is allocated, and have 
> all members implicitly initialized to zero.
> 
> Signed-off-by: Nicolas Pitre <nico@cam.org>
> ---
> diff --git a/sha1_file.c b/sha1_file.c
> index a92f023..c56f674 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -792,18 +792,28 @@ unsigned char* use_pack(struct packed_git *p,
>  	return win->base + offset;
>  }
>  
> +static struct packed_git *alloc_packed_git(int extra)
> +{
> +	struct packed_git *p = xmalloc(sizeof(*p) + extra);
> +	memset(p, 0, sizeof(*p));
> +	p->pack_fd = -1;
> +	return p;
> +}
Nit:  That's an explicit 0 initialization!
jdl
Previous: Nicolas PitreNext: Junio C Hamano
Message 2 of 5 in “factorize pack structure allocation”
  1. factorize pack structure allocationNicolas Pitre, Jun 24, 2008
  2. Jon LoeligerJun 24, 2008
  3. Junio C HamanoJun 25, 2008
  4. Teemu LikonenJun 25, 2008
  5. Andreas EricssonJun 26, 2008

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.