@matheusbsbs / matheus-bagliano / commits / cc21682793
Fork 0

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>

Jim Meyering committed Dec 21, 2007 at 11:56 UTC cc216827936e40bc2e8886623fd44f55e0674932
1 file changed +22 -13
object.c
+22 -13
@@ -136,29 +136,38 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
136 struct object *obj;
137 int eaten = 0;
138
139 + obj = NULL;
140 if (type == OBJ_BLOB) {
141 struct blob *blob = lookup_blob(sha1);
141 - parse_blob_buffer(blob, buffer, size);
142 - obj = &blob->object;
142 + if (blob) {
143 + parse_blob_buffer(blob, buffer, size);
144 + obj = &blob->object;
145 + }
146 } else if (type == OBJ_TREE) {
147 struct tree *tree = lookup_tree(sha1);
145 - obj = &tree->object;
146 - if (!tree->object.parsed) {
147 - parse_tree_buffer(tree, buffer, size);
148 - eaten = 1;
148 + if (tree) {
149 + obj = &tree->object;
150 + if (!tree->object.parsed) {
151 + parse_tree_buffer(tree, buffer, size);
152 + eaten = 1;
153 + }
154 }
155 } else if (type == OBJ_COMMIT) {
156 struct commit *commit = lookup_commit(sha1);
152 - parse_commit_buffer(commit, buffer, size);
153 - if (!commit->buffer) {
154 - commit->buffer = buffer;
155 - eaten = 1;
157 + if (commit) {
158 + parse_commit_buffer(commit, buffer, size);
159 + if (!commit->buffer) {
160 + commit->buffer = buffer;
161 + eaten = 1;
162 + }
163 + obj = &commit->object;
164 }
157 - obj = &commit->object;
165 } else if (type == OBJ_TAG) {
166 struct tag *tag = lookup_tag(sha1);
160 - parse_tag_buffer(tag, buffer, size);
161 - obj = &tag->object;
167 + if (tag) {
168 + parse_tag_buffer(tag, buffer, size);
169 + obj = &tag->object;
170 + }
171 } else {
172 warning("object %s has unknown type id %d\n", sha1_to_hex(sha1), type);
173 obj = NULL;