{"thread":{"id":"41080","subject":"[PATCH] dir.c: clean the entire struct in clear_exclude_list()","startedAt":"2015-12-27T01:54:34Z","lastAt":"2015-12-28T20:47:58Z","messageCount":2,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"275015","messageId":"1451181274-26213-1-git-send-email-pclouds@gmail.com","threadId":"41080","inReplyTo":null,"subject":"[PATCH] dir.c: clean the entire struct in clear_exclude_list()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2015-12-27T01:54:34Z","receivedAt":"2015-12-27T01:54:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Make sure \"el\" can be reuseable again. The problem was el->alloc is\nnot cleared and may cause segfaults next time because add_exclude()\nthinks el->excludes (being NULL) has enough space. Just clear the\nentire struct to be safe.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n This was needed in the worktree config split series because the same\n exclude_list could be reused. But that series is changing and will not\n need exclude_list any more. So instead of dropping this patch, I\n submit it separately. It's a good fix anyway.\n\n dir.c | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex d2a8f06..b8b4576 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -564,9 +564,7 @@ void clear_exclude_list(struct exclude_list *el)\n \tfree(el->excludes);\n \tfree(el->filebuf);\n \n-\tel->nr = 0;\n-\tel->excludes = NULL;\n-\tel->filebuf = NULL;\n+\tmemset(el, 0, sizeof(*el));\n }\n \n static void trim_trailing_spaces(char *buf)\n-- \n2.3.0.rc1.137.g477eb31\n"},{"id":"275056","messageId":"xmqqtwn2jo5d.fsf@gitster.mtv.corp.google.com","threadId":"41080","inReplyTo":"1451181274-26213-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] dir.c: clean the entire struct in clear_exclude_list()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-12-28T20:47:58Z","receivedAt":"2015-12-28T20:47:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Make sure \"el\" can be reuseable again. The problem was el->alloc is\n> not cleared and may cause segfaults next time because add_exclude()\n> thinks el->excludes (being NULL) has enough space. Just clear the\n> entire struct to be safe.\n\nOK.\n\nIf somebody ever adds a field to this structure that should not be\ncleared by filling it with '\\0', that person would notice and turn\nthis memset() back to individual field assignment, but until then,\nI think memset is a reasonable thing to do, as that is how it is\ninitialized by add_exclude_list() in the first place anyway.\n\nWill apply.\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  This was needed in the worktree config split series because the same\n>  exclude_list could be reused. But that series is changing and will not\n>  need exclude_list any more. So instead of dropping this patch, I\n>  submit it separately. It's a good fix anyway.\n>\n>  dir.c | 4 +---\n>  1 file changed, 1 insertion(+), 3 deletions(-)\n>\n> diff --git a/dir.c b/dir.c\n> index d2a8f06..b8b4576 100644\n> --- a/dir.c\n> +++ b/dir.c\n> @@ -564,9 +564,7 @@ void clear_exclude_list(struct exclude_list *el)\n>  \tfree(el->excludes);\n>  \tfree(el->filebuf);\n>  \n> -\tel->nr = 0;\n> -\tel->excludes = NULL;\n> -\tel->filebuf = NULL;\n> +\tmemset(el, 0, sizeof(*el));\n>  }\n>  \n>  static void trim_trailing_spaces(char *buf)\n"}]}