diff options
author | Russell Belfer <rb@github.com> | 2012-09-11 17:26:21 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-09-11 17:26:21 -0700 |
commit | a13fb55afdbf9d74c3d4b6aa76476a005da49486 (patch) | |
tree | 9755770eed5893cce9d69e22f4f5a773d8c99220 /src | |
parent | 47bfa0be6d509b60eda92705b57d3f7ba89c1c6b (diff) | |
download | libgit2-a13fb55afdbf9d74c3d4b6aa76476a005da49486.tar.gz |
Add tests and improve param checks
Fixed some minor `git_repository_hashfile` issues:
- Fixed incorrect doc (saying that repo could be NULL)
- Added checking of object type value to acceptable ones
- Added more tests for various parameter permutations
Diffstat (limited to 'src')
-rw-r--r-- | src/odb.c | 5 | ||||
-rw-r--r-- | src/repository.c | 7 |
2 files changed, 11 insertions, 1 deletions
@@ -117,6 +117,11 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type) git_hash_ctx *ctx; ssize_t read_len; + if (!git_object_typeisloose(type)) { + giterr_set(GITERR_INVALID, "Invalid object type for hash"); + return -1; + } + hdr_len = format_object_header(hdr, sizeof(hdr), size, type); ctx = git_hash_new_ctx(); diff --git a/src/repository.c b/src/repository.c index ab139a723..bcc6b1503 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1388,7 +1388,12 @@ int git_repository_hashfile( git_off_t len; git_buf full_path = GIT_BUF_INIT; - assert(out && path); /* repo and as_path can be NULL */ + assert(out && path && repo); /* as_path can be NULL */ + + /* At some point, it would be nice if repo could be NULL to just + * apply filter rules defined in system and global files, but for + * now that is not possible because git_filters_load() needs it. + */ error = git_path_join_unrooted( &full_path, path, repo ? git_repository_workdir(repo) : NULL, NULL); |