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

Re: [PATCH] dir.c: clean the entire struct in clear_exclude_list()

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 28, 2015, 20:47 UTC
Message-ID
<xmqqtwn2jo5d.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1451181274-26213-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> Make sure "el" can be reuseable again. The problem was el->alloc is
> not cleared and may cause segfaults next time because add_exclude()
> thinks el->excludes (being NULL) has enough space. Just clear the
> entire struct to be safe.
OK.

If somebody ever adds a field to this structure that should not be cleared by filling it with '\0', that person would notice and turn this memset() back to individual field assignment, but until then, I think memset is a reasonable thing to do, as that is how it is initialized by add_exclude_list() in the first place anyway.

Will apply.
Show 25 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  This was needed in the worktree config split series because the same
>  exclude_list could be reused. But that series is changing and will not
>  need exclude_list any more. So instead of dropping this patch, I
>  submit it separately. It's a good fix anyway.
>
>  dir.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/dir.c b/dir.c
> index d2a8f06..b8b4576 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -564,9 +564,7 @@ void clear_exclude_list(struct exclude_list *el)
>  	free(el->excludes);
>  	free(el->filebuf);
>  
> -	el->nr = 0;
> -	el->excludes = NULL;
> -	el->filebuf = NULL;
> +	memset(el, 0, sizeof(*el));
>  }
>  
>  static void trim_trailing_spaces(char *buf)
Previous: Nguyễn Thái Ngọc Duy
Message 2 of 2 in “dir.c: clean the entire struct in clear_exclude_list()”
  1. dir.c: clean the entire struct in clear_exclude_list()Nguyễn Thái Ngọc Duy, Dec 27, 2015
  2. Junio C HamanoDec 28, 2015

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.