summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2007-12-21 10:56:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-12-22 19:15:38 (GMT)
commitcc216827936e40bc2e8886623fd44f55e0674932 (patch)
tree89b9c3ccbf54a1eba855b4446f3f2903e69794dc /object.c
parent97bc00a4909fb73eba8a05dc89fe7914d7123245 (diff)
downloadgit-cc216827936e40bc2e8886623fd44f55e0674932.zip
git-cc216827936e40bc2e8886623fd44f55e0674932.tar.gz
git-cc216827936e40bc2e8886623fd44f55e0674932.tar.bz2
Don't dereference NULL upon lookup failure.
Instead, signal the error just like the case we do upon encountering an object with an unknown type. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.c')
-rw-r--r--object.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/object.c b/object.c
index 16793d9..5a5ebe2 100644
--- a/object.c
+++ b/object.c
@@ -136,29 +136,38 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
struct object *obj;
int eaten = 0;
+ obj = NULL;
if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(sha1);
- parse_blob_buffer(blob, buffer, size);
- obj = &blob->object;
+ if (blob) {
+ parse_blob_buffer(blob, buffer, size);
+ obj = &blob->object;
+ }
} else if (type == OBJ_TREE) {
struct tree *tree = lookup_tree(sha1);
- obj = &tree->object;
- if (!tree->object.parsed) {
- parse_tree_buffer(tree, buffer, size);
- eaten = 1;
+ if (tree) {
+ obj = &tree->object;
+ if (!tree->object.parsed) {
+ parse_tree_buffer(tree, buffer, size);
+ eaten = 1;
+ }
}
} else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(sha1);
- parse_commit_buffer(commit, buffer, size);
- if (!commit->buffer) {
- commit->buffer = buffer;
- eaten = 1;
+ if (commit) {
+ parse_commit_buffer(commit, buffer, size);
+ if (!commit->buffer) {
+ commit->buffer = buffer;
+ eaten = 1;
+ }
+ obj = &commit->object;
}
- obj = &commit->object;
} else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(sha1);
- parse_tag_buffer(tag, buffer, size);
- obj = &tag->object;
+ if (tag) {
+ parse_tag_buffer(tag, buffer, size);
+ obj = &tag->object;
+ }
} else {
warning("object %s has unknown type id %d\n", sha1_to_hex(sha1), type);
obj = NULL;