Skip to content

Commit f054996

Browse files
pcloudsgitster
authored andcommitted
worktree.c: zero new 'struct worktree' on allocation
This keeps things a bit simpler when we add more fields, knowing that default values are always zero. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e37181 commit f054996

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

worktree.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,11 @@ static struct worktree *get_main_worktree(void)
9191
if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
9292
goto done;
9393

94-
worktree = xmalloc(sizeof(struct worktree));
94+
worktree = xcalloc(1, sizeof(*worktree));
9595
worktree->path = strbuf_detach(&worktree_path, NULL);
96-
worktree->id = NULL;
9796
worktree->is_bare = is_bare;
98-
worktree->head_ref = NULL;
9997
worktree->is_detached = is_detached;
100-
worktree->is_current = 0;
10198
add_head_info(&head_ref, worktree);
102-
worktree->lock_reason = NULL;
103-
worktree->lock_reason_valid = 0;
10499

105100
done:
106101
strbuf_release(&path);
@@ -138,16 +133,11 @@ static struct worktree *get_linked_worktree(const char *id)
138133
if (parse_ref(path.buf, &head_ref, &is_detached) < 0)
139134
goto done;
140135

141-
worktree = xmalloc(sizeof(struct worktree));
136+
worktree = xcalloc(1, sizeof(*worktree));
142137
worktree->path = strbuf_detach(&worktree_path, NULL);
143138
worktree->id = xstrdup(id);
144-
worktree->is_bare = 0;
145-
worktree->head_ref = NULL;
146139
worktree->is_detached = is_detached;
147-
worktree->is_current = 0;
148140
add_head_info(&head_ref, worktree);
149-
worktree->lock_reason = NULL;
150-
worktree->lock_reason_valid = 0;
151141

152142
done:
153143
strbuf_release(&path);

0 commit comments

Comments
 (0)