Skip to content

Commit b1f4a09

Browse files
dschogitster
authored andcommitted
inherit_tracking(): defensive programming
CodeQL points out that `branch_get()` can return NULL values. Note that the error path in this instance calls `BUG()`, not `die()`, for two reasons: 1. The code lives in `libgit.a` and calling `die()` from within those library functions is a bad practice that needs to be reduced, rather than increased. 2. The `inherit_tracking()` function really should only be called with the name of an existing branch, therefore a `NULL` return value would indeed constitute a bug in Git's code. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b05d455 commit b1f4a09

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

branch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
224224
skip_prefix(orig_ref, "refs/heads/", &bare_ref);
225225

226226
branch = branch_get(bare_ref);
227+
if (!branch)
228+
BUG("could not get branch for '%s", bare_ref);
227229
if (!branch->remote_name) {
228230
warning(_("asked to inherit tracking from '%s', but no remote is set"),
229231
bare_ref);

0 commit comments

Comments
 (0)