Skip to content

Commit 0a82617

Browse files
dschogitster
authored andcommitted
fetch: defensive programming
CodeQL points out that `branch_get()` can return NULL values. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abba7ee commit 0a82617

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

builtin/fetch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ static struct ref *get_ref_map(struct remote *remote,
552552
if (remote &&
553553
(remote->fetch.nr ||
554554
/* Note: has_merge implies non-NULL branch->remote_name */
555-
(has_merge && !strcmp(branch->remote_name, remote->name)))) {
555+
(has_merge && branch && !strcmp(branch->remote_name, remote->name)))) {
556556
for (i = 0; i < remote->fetch.nr; i++) {
557557
get_fetch_map(remote_refs, &remote->fetch.items[i], &tail, 0);
558558
if (remote->fetch.items[i].dst &&
@@ -570,6 +570,7 @@ static struct ref *get_ref_map(struct remote *remote,
570570
* Note: has_merge implies non-NULL branch->remote_name
571571
*/
572572
if (has_merge &&
573+
branch &&
573574
!strcmp(branch->remote_name, remote->name))
574575
add_merge_config(&ref_map, remote_refs, branch, &tail);
575576
} else if (!prefetch) {

0 commit comments

Comments
 (0)