diff --git a/docs/error-handling.md b/docs/error-handling.md index 2dbe64a715a..719244d2fd7 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -128,7 +128,7 @@ The public error API bugs, but in the meantime, please code defensively and check for NULL when calling this function. -- `void geterr_clear(void)`: This function clears the last error. The +- `void giterr_clear(void)`: This function clears the last error. The library will call this when an error is generated by low level function and the higher level function handles the error. diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 921f7862bfc..9f87b30d491 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -1463,7 +1463,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) entry = git__calloc(1, sizeof(git_reflog_entry)); GITERR_CHECK_ALLOC(entry); - entry->committer = git__malloc(sizeof(git_signature)); + entry->committer = git__calloc(1, sizeof(git_signature)); GITERR_CHECK_ALLOC(entry->committer); if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < 0) diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index 56ec422c39c..d2b8e0fa35a 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -154,6 +154,22 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re git_buf_free(&subtrees_log_path); } +void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error(void) +{ + git_reflog *reflog; + const git_error *error; + + /* clear the error state so we can capture the error generated by git_reflog_read */ + giterr_clear(); + + cl_git_fail(git_reflog_read(&reflog, g_repo, "refs/heads/extra-newline")); + + error = giterr_last(); + + cl_assert(error != NULL); + cl_assert_equal_s("Unable to parse OID - contains invalid characters", error->message); +} + void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void) { git_reference *master, *new_master; diff --git a/tests/resources/testrepo.git/logs/refs/heads/extra-newline b/tests/resources/testrepo.git/logs/refs/heads/extra-newline new file mode 100644 index 00000000000..c809e013769 --- /dev/null +++ b/tests/resources/testrepo.git/logs/refs/heads/extra-newline @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 be3563ae3f795b2b4353bcce3a527ad0a4f7f644 Ben Straub 1335806563 -0800 clone: from +/Users/ben/src/libgit2/tests/resources/testrepo.git +be3563ae3f795b2b4353bcce3a527ad0a4f7f644 a65fedf39aefe402d3bb6e24df4d4f5fe4547750 Ben Straub 1335806603 -0800 commit: checking in