]> git.ipfire.org Git - thirdparty/git.git/commitdiff
am: simplify building "show" argument list
authorRené Scharfe <l.s.r@web.de>
Sun, 30 Oct 2022 11:46:11 +0000 (12:46 +0100)
committerTaylor Blau <me@ttaylorr.com>
Sun, 30 Oct 2022 18:04:33 +0000 (14:04 -0400)
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>
builtin/am.c

index 39fea24833078be76d76d974e5b601715ed51aea..5781e7a95ec3013a5439ae2f8db2bf16b3920d13 100644 (file)
@@ -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) {