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 <l.s.r@web.de> Signed-off-by: Taylor Blau <me@ttaylorr.com>

René Scharfe committed Oct 30, 2022 at 12:46 UTC 75c92a0540dd866b1ccf5454c4cc540d926a6139
1 file changed +4 -7
builtin/am.c
+4 -7
@@ -2187,14 +2187,11 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
2187 int len;
2188
2189 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 + };
2193
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);
2195 }
2196
2197 switch (sub_mode) {