Skip to content

Commit 75c92a0

Browse files
rscharfettaylorr
authored andcommitted
am: simplify building "show" argument list
Build the string array av during initialization, without any magic numbers or heap allocations. Not duplicating the result of oid_to_hex() is safe because run_command_v_opt() duplicates all arguments already. (It would even be safe if it didn't, but that's a different story.) Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 53c4be3 commit 75c92a0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

builtin/am.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,14 +2187,11 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
21872187
int len;
21882188

21892189
if (!is_null_oid(&state->orig_commit)) {
2190-
const char *av[4] = { "show", NULL, "--", NULL };
2191-
char *new_oid_str;
2192-
int ret;
2190+
const char *av[] = {
2191+
"show", oid_to_hex(&state->orig_commit), "--", NULL
2192+
};
21932193

2194-
av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
2195-
ret = run_command_v_opt(av, RUN_GIT_CMD);
2196-
free(new_oid_str);
2197-
return ret;
2194+
return run_command_v_opt(av, RUN_GIT_CMD);
21982195
}
21992196

22002197
switch (sub_mode) {

0 commit comments

Comments
 (0)