summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2014-11-21 13:50:46 +0100
committerVicent Marti <tanoku@gmail.com>2014-11-21 14:09:53 +0100
commite015665142fad7314581063b25202f32631d510e (patch)
treec3aeae51d9e4f367438a4e9b70b2353ba069d903
parentfc6ac074ee7ea945819e0a1d6f65ba160ba403d7 (diff)
downloadlibgit2-vmg/empty.tar.gz
odb: `git_odb_object` contents are never NULLvmg/empty
This is a contract that we made in the library and that we need to uphold. The contents of a blob can never be NULL because several parts of the library (including the filter and attributes code) expect `git_blob_rawcontent` to always return a valid pointer.
-rw-r--r--src/odb.c4
-rw-r--r--tests/odb/emptyobjects.c18
2 files changed, 20 insertions, 2 deletions
diff --git a/src/odb.c b/src/odb.c
index 2c19c0311..5961b35a7 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -762,12 +762,12 @@ static int hardcoded_objects(git_rawobj *raw, const git_oid *id)
if (!git_oid_cmp(id, &empty_blob)) {
raw->type = GIT_OBJ_BLOB;
raw->len = 0;
- raw->data = NULL;
+ raw->data = git__calloc(1, sizeof(uint8_t));
return 0;
} else if (!git_oid_cmp(id, &empty_tree)) {
raw->type = GIT_OBJ_TREE;
raw->len = 0;
- raw->data = NULL;
+ raw->data = git__calloc(1, sizeof(uint8_t));
return 0;
} else {
return GIT_ENOTFOUND;
diff --git a/tests/odb/emptyobjects.c b/tests/odb/emptyobjects.c
index d6d832cdf..783d05197 100644
--- a/tests/odb/emptyobjects.c
+++ b/tests/odb/emptyobjects.c
@@ -21,6 +21,8 @@ void test_odb_emptyobjects__read(void)
cl_git_pass(git_oid_fromstr(&id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_assert_equal_i(GIT_OBJ_BLOB, git_object_type((git_object *) blob));
+ cl_assert(git_blob_rawcontent(blob));
+ cl_assert_equal_s("", git_blob_rawcontent(blob));
cl_assert_equal_i(0, git_blob_rawsize(blob));
git_blob_free(blob);
}
@@ -37,3 +39,19 @@ void test_odb_emptyobjects__read_tree(void)
cl_assert_equal_p(NULL, git_tree_entry_byname(tree, "foo"));
git_tree_free(tree);
}
+
+void test_odb_emptyobjects__read_tree_odb(void)
+{
+ git_oid id;
+ git_odb *odb;
+ git_odb_object *tree_odb;
+
+ cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904"));
+ cl_git_pass(git_repository_odb(&odb, g_repo));
+ cl_git_pass(git_odb_read(&tree_odb, odb, &id));
+ cl_assert(git_odb_object_data(tree_odb));
+ cl_assert_equal_s("", git_odb_object_data(tree_odb));
+ cl_assert_equal_i(0, git_odb_object_size(tree_odb));
+ git_odb_object_free(tree_odb);
+ git_odb_free(odb);
+}