]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hook: check for NULL pointer before deref
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Fri, 9 Jan 2026 18:19:12 +0000 (20:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jan 2026 21:10:30 +0000 (13:10 -0800)
Fix a compiler warning (-Werror=analyzer-deref-before-check) due to
dereferencing the options pointer before NULL checking it.

In practice run_hooks_opt() is never called with a NULL opt struct,
so this just fixes the code to not trigger the warning anymore.

The NULL check is kept as-is because some future patches might end up
calling run_hooks_opt with a NULL opt struct, which is clearly a bug.

While at it, also fix the BUG message function name.

Reported-by: correctmost <cmlists@sent.com>
Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hook.c

diff --git a/hook.c b/hook.c
index 35211e5ed7c474966a3d0e15ff8d74a12fd4c409..6b8ddfe7b603841b819493c37e4b6119eb1be00b 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -148,28 +148,29 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
        };
        const char *const hook_path = find_hook(r, hook_name);
        int ret = 0;
-       const struct run_process_parallel_opts opts = {
+       struct run_process_parallel_opts opts = {
                .tr2_category = "hook",
                .tr2_label = hook_name,
 
                .processes = 1,
-               .ungroup = options->ungroup,
 
                .get_next_task = pick_next_hook,
                .start_failure = notify_start_failure,
-               .feed_pipe = options->feed_pipe,
-               .consume_output = options->consume_output,
                .task_finished = notify_hook_finished,
 
                .data = &cb_data,
        };
 
        if (!options)
-               BUG("a struct run_hooks_opt must be provided to run_hooks");
+               BUG("a struct run_hooks_opt must be provided to run_hooks_opt");
 
        if (options->path_to_stdin && options->feed_pipe)
                BUG("options path_to_stdin and feed_pipe are mutually exclusive");
 
+       opts.ungroup = options->ungroup;
+       opts.feed_pipe = options->feed_pipe;
+       opts.consume_output = options->consume_output;
+
        if (options->invoked_hook)
                *options->invoked_hook = 0;