summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-07-06 23:37:44 +0200
committernulltoken <emeric.fermas@gmail.com>2012-07-07 12:16:14 +0200
commitb8460c2015d0954f3317caf60c1e49fb3cd56ace (patch)
treef3684a384c60eb03f7f75a2f9abf2b0398f89409
parente727938112a45a3ef9b8751aaef96d4ff7da74b2 (diff)
downloadlibgit2-b8460c2015d0954f3317caf60c1e49fb3cd56ace.tar.gz
revparse: do not segfault when retrieving the last entry
-rw-r--r--src/revparse.c2
-rw-r--r--tests-clar/refs/revparse.c1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/revparse.c b/src/revparse.c
index 47437f355..3194cc491 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -263,7 +263,7 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
retcode = revparse_lookup_fully_qualifed_ref(out, repo, git_buf_cstr(&buf));
else if (!git_reflog_read(&reflog, disambiguated)) {
int numentries = git_reflog_entrycount(reflog);
- if (numentries < n) {
+ if (numentries < n + 1) {
giterr_set(GITERR_REFERENCE, "Reflog for '%s' has only %d entries, asked for %d",
git_buf_cstr(&buf), numentries, n);
retcode = GIT_ENOTFOUND;
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 3f4fcd68b..f723a1426 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -156,6 +156,7 @@ void test_refs_revparse__ordinal(void)
test_object("nope@{0}", NULL);
test_object("master@{31415}", NULL);
test_object("@{1000}", NULL);
+ test_object("@{2}", NULL);
test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");