]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replay: move onto NULL check before first use
authorRené Scharfe <l.s.r@web.de>
Thu, 11 Dec 2025 17:56:54 +0000 (18:56 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2025 03:41:26 +0000 (12:41 +0900)
cmd_replay() aborts if the pointer "onto" is NULL after argument
parsing, e.g. when specifying a non-existing commit with --onto.
15cd4ef1f4 (replay: make atomic ref updates the default behavior,
2025-11-06) added code that dereferences this pointer before the check.
Switch their places to avoid a segmentation fault.

Reported-by: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/replay.c

index 6606a2c94bc67168c2b43e86f24717eb408e6f38..312b8203cb525a477373778463bbc0b711afde5b 100644 (file)
@@ -454,6 +454,9 @@ int cmd_replay(int argc,
        determine_replay_mode(repo, &revs.cmdline, onto_name, &advance_name,
                              &onto, &update_refs);
 
+       if (!onto) /* FIXME: Should handle replaying down to root commit */
+               die("Replaying down to root commit is not supported yet!");
+
        /* Build reflog message */
        if (advance_name_opt)
                strbuf_addf(&reflog_msg, "replay --advance %s", advance_name_opt);
@@ -472,9 +475,6 @@ int cmd_replay(int argc,
                }
        }
 
-       if (!onto) /* FIXME: Should handle replaying down to root commit */
-               die("Replaying down to root commit is not supported yet!");
-
        if (prepare_revision_walk(&revs) < 0) {
                ret = error(_("error preparing revisions"));
                goto cleanup;