[PATCH v2 03/12] am: simplify building "show" argument list
- From
René Scharfe <l.s.r@web.de>
- Date
- Oct 30, 2022, 11:46 UTC
- Message-ID
- <e3a5cf13-d1c7-20b3-3f40-3eaff5a18b67@web.de>
- In-Reply-To
- <ea061164-b36b-485c-963f-8c13e813a47e@web.de>
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> --- builtin/am.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c index 39fea24833..5781e7a95e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2187,14 +2187,11 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode) int len; if (!is_null_oid(&state->orig_commit)) { - const char *av[4] = { "show", NULL, "--", NULL }; - char *new_oid_str; - int ret; + const char *av[] = { + "show", oid_to_hex(&state->orig_commit), "--", NULL + }; - av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit)); - ret = run_command_v_opt(av, RUN_GIT_CMD); - free(new_oid_str); - return ret; + return run_command_v_opt(av, RUN_GIT_CMD); } switch (sub_mode) { -- 2.38.1