Re: [PATCH 03/11] remote: guard `remote_tracking()` against NULL remote
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 10, 2026, 03:21 UTC
- Message-ID
- <xmqqh5m7h6n5.fsf@gitster.g>
- In-Reply-To
- <dcaefc598779123cea19807877e074acb3e1575a.1783590159.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
> However, it requires quite involved reasoning to reach that conclusion,
> and is therefore fragile. Just return -1 ("no tracking ref") when there
> is no remote to work with.In a case like this, where the function is designed not to be called with NULL remote, I would prefer to have an explicit BUG() rather than sweeping the problem under the rug. That would make sure your investigation and involved reasoning done here remain relevant if the BUG() triggers due to careless changes to the caller in the future.
Thanks.
Show 21 quoted lines
> Pointed out by Coverity.
>
> Assisted-by: Claude Opus 4.6
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> remote.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/remote.c b/remote.c
> index 00723b385e..34d0367f11 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -2681,6 +2681,8 @@ static int remote_tracking(struct remote *remote, const char *refname,
> {
> char *dst;
>
> + if (!remote)
> + return -1; /* no remote to look up tracking ref */
> dst = apply_refspecs(&remote->fetch, refname);
> if (!dst)
> return -1; /* no tracking ref for refname at remote */