Skip to content

Commit 16d2676

Browse files
peffgitster
authored andcommitted
am: drop "dir" parameter from am_state_init
The only caller of this function passes in a static buffer returned from git_path(). This looks dangerous at first glance, but turns out to be OK because the first thing we do is xstrdup() the result. Let's turn this into a git_pathdup(). That's slightly more efficient (no extra copy), and makes it easier to audit for dangerous git_path() invocations. Since there's only a single caller, let's just set this default path inside the init function. That makes the memory ownership clear. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c2ca3a commit 16d2676

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

builtin/am.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,15 @@ struct am_state {
134134
};
135135

136136
/**
137-
* Initializes am_state with the default values. The state directory is set to
138-
* dir.
137+
* Initializes am_state with the default values.
139138
*/
140-
static void am_state_init(struct am_state *state, const char *dir)
139+
static void am_state_init(struct am_state *state)
141140
{
142141
int gpgsign;
143142

144143
memset(state, 0, sizeof(*state));
145144

146-
assert(dir);
147-
state->dir = xstrdup(dir);
145+
state->dir = git_pathdup("rebase-apply");
148146

149147
state->prec = 4;
150148

@@ -2322,7 +2320,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23222320

23232321
git_config(git_am_config, NULL);
23242322

2325-
am_state_init(&state, git_path("rebase-apply"));
2323+
am_state_init(&state);
23262324

23272325
in_progress = am_in_progress(&state);
23282326
if (in_progress)

0 commit comments

Comments
 (0)