summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-02-14 13:49:35 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-14 14:01:27 +0100
commit788cd2d5f070c496e5f66467d92bfd714f2878f4 (patch)
treeccacf47aa7503cfa207d05f0a50a06703a7e414f /src/branch.c
parenta0f87e161b000558ed4aba70bfeb88ddf3329583 (diff)
downloadlibgit2-788cd2d5f070c496e5f66467d92bfd714f2878f4.tar.gz
branches: do not assert that the given ref is a branch
Libraries should use assert(3P) only very scarcely. First, we usually shouldn't cause the caller of our library to abort in case where the assert fails. Second, if code is compiled with -DNDEBUG, then the assert will not be included at all. In our `git_branch_is_checked_out` function, we have an assert that verifies that the given reference parameter is non-NULL and in fact a branch. While the first check is fine, the second is not. E.g. when compiled with -DNDEBUG, we'd proceed and treat the given reference as a branch in all cases. Fix the issue by instead treating a non-branch reference as not being checked out. This is the obvious solution, as references other than branches cannot be directly checked out.
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/branch.c b/src/branch.c
index 61ed03e2e..516a87f31 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -153,7 +153,10 @@ done:
int git_branch_is_checked_out(const git_reference *branch)
{
- assert(branch && git_reference_is_branch(branch));
+ assert(branch);
+
+ if (!git_reference_is_branch(branch))
+ return 0;
return git_repository_foreach_head(git_reference_owner(branch),
branch_equals, (void *) branch) == 1;