revparse: do not segfault when retrieving the last entry

This commit is contained in:
nulltoken 2012-07-06 23:37:44 +02:00
parent e727938112
commit b8460c2015
2 changed files with 2 additions and 1 deletions

View File

@ -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)); retcode = revparse_lookup_fully_qualifed_ref(out, repo, git_buf_cstr(&buf));
else if (!git_reflog_read(&reflog, disambiguated)) { else if (!git_reflog_read(&reflog, disambiguated)) {
int numentries = git_reflog_entrycount(reflog); 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", giterr_set(GITERR_REFERENCE, "Reflog for '%s' has only %d entries, asked for %d",
git_buf_cstr(&buf), numentries, n); git_buf_cstr(&buf), numentries, n);
retcode = GIT_ENOTFOUND; retcode = GIT_ENOTFOUND;

View File

@ -156,6 +156,7 @@ void test_refs_revparse__ordinal(void)
test_object("nope@{0}", NULL); test_object("nope@{0}", NULL);
test_object("master@{31415}", NULL); test_object("master@{31415}", NULL);
test_object("@{1000}", NULL); test_object("@{1000}", NULL);
test_object("@{2}", NULL);
test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");