* [PATCH] dir.c: clean the entire struct in clear_exclude_list()
@ 2015-12-27 1:54 Nguyễn Thái Ngọc Duy
2015-12-28 20:47 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2015-12-27 1:54 UTC (permalink / raw)
To: git; +Cc: Nguyễn Thái Ngọc Duy
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.
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)
--
2.3.0.rc1.137.g477eb31
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] dir.c: clean the entire struct in clear_exclude_list()
2015-12-27 1:54 [PATCH] dir.c: clean the entire struct in clear_exclude_list() Nguyễn Thái Ngọc Duy
@ 2015-12-28 20:47 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2015-12-28 20:47 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
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.
> 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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-28 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-27 1:54 [PATCH] dir.c: clean the entire struct in clear_exclude_list() Nguyễn Thái Ngọc Duy
2015-12-28 20:47 ` Junio C Hamano
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).