mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
97bc00a490
commit
cc21682793
35
object.c
35
object.c
@@ -136,29 +136,38 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
|
|||||||
struct object *obj;
|
struct object *obj;
|
||||||
int eaten = 0;
|
int eaten = 0;
|
||||||
|
|
||||||
|
obj = NULL;
|
||||||
if (type == OBJ_BLOB) {
|
if (type == OBJ_BLOB) {
|
||||||
struct blob *blob = lookup_blob(sha1);
|
struct blob *blob = lookup_blob(sha1);
|
||||||
parse_blob_buffer(blob, buffer, size);
|
if (blob) {
|
||||||
obj = &blob->object;
|
parse_blob_buffer(blob, buffer, size);
|
||||||
|
obj = &blob->object;
|
||||||
|
}
|
||||||
} else if (type == OBJ_TREE) {
|
} else if (type == OBJ_TREE) {
|
||||||
struct tree *tree = lookup_tree(sha1);
|
struct tree *tree = lookup_tree(sha1);
|
||||||
obj = &tree->object;
|
if (tree) {
|
||||||
if (!tree->object.parsed) {
|
obj = &tree->object;
|
||||||
parse_tree_buffer(tree, buffer, size);
|
if (!tree->object.parsed) {
|
||||||
eaten = 1;
|
parse_tree_buffer(tree, buffer, size);
|
||||||
|
eaten = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (type == OBJ_COMMIT) {
|
} else if (type == OBJ_COMMIT) {
|
||||||
struct commit *commit = lookup_commit(sha1);
|
struct commit *commit = lookup_commit(sha1);
|
||||||
parse_commit_buffer(commit, buffer, size);
|
if (commit) {
|
||||||
if (!commit->buffer) {
|
parse_commit_buffer(commit, buffer, size);
|
||||||
commit->buffer = buffer;
|
if (!commit->buffer) {
|
||||||
eaten = 1;
|
commit->buffer = buffer;
|
||||||
|
eaten = 1;
|
||||||
|
}
|
||||||
|
obj = &commit->object;
|
||||||
}
|
}
|
||||||
obj = &commit->object;
|
|
||||||
} else if (type == OBJ_TAG) {
|
} else if (type == OBJ_TAG) {
|
||||||
struct tag *tag = lookup_tag(sha1);
|
struct tag *tag = lookup_tag(sha1);
|
||||||
parse_tag_buffer(tag, buffer, size);
|
if (tag) {
|
||||||
obj = &tag->object;
|
parse_tag_buffer(tag, buffer, size);
|
||||||
|
obj = &tag->object;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
warning("object %s has unknown type id %d\n", sha1_to_hex(sha1), type);
|
warning("object %s has unknown type id %d\n", sha1_to_hex(sha1), type);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user