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

deref_tag: handle return value NULL

Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Koegler committed Feb 18, 2008 at 08:31 UTC affeef12fb2d10317fbcc7a866fbc3603cf16119
5 files changed +12 -3
builtin-show-ref.c
+3
@@ -86,6 +86,9 @@ match:
86 sha1_to_hex(sha1));
87 if (obj->type == OBJ_TAG) {
88 obj = deref_tag(obj, refname, 0);
89 + if (!obj)
90 + die("git-show-ref: bad tag at ref %s (%s)", refname,
91 + sha1_to_hex(sha1));
92 hex = find_unique_abbrev(obj->sha1, abbrev);
93 printf("%s %s^{}\n", hex, refname);
94 }
merge-recursive.c
+2
@@ -1673,6 +1673,8 @@ static struct commit *get_ref(const char *ref)
1673 if (get_sha1(ref, sha1))
1674 die("Could not resolve ref '%s'", ref);
1675 object = deref_tag(parse_object(sha1), ref, strlen(ref));
1676 + if (!object)
1677 + return NULL;
1678 if (object->type == OBJ_TREE)
1679 return make_virtual_commit((struct tree*)object,
1680 better_branch_name(ref));
sha1_name.c
+4 -1
@@ -578,8 +578,11 @@ static int handle_one_ref(const char *path,
578 struct object *object = parse_object(sha1);
579 if (!object)
580 return 0;
581 - if (object->type == OBJ_TAG)
581 + if (object->type == OBJ_TAG) {
582 object = deref_tag(object, path, strlen(path));
583 + if (!object)
584 + return 0;
585 + }
586 if (object->type != OBJ_COMMIT)
587 return 0;
588 insert_by_date((struct commit *)object, list);
shallow.c
+1 -1
@@ -56,7 +56,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
56 if (i < heads->nr) {
57 commit = (struct commit *)
58 deref_tag(heads->objects[i++].item, NULL, 0);
59 - if (commit->object.type != OBJ_COMMIT) {
59 + if (!commit || commit->object.type != OBJ_COMMIT) {
60 commit = NULL;
61 continue;
62 }
upload-pack.c
+2 -1
@@ -575,7 +575,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
575 }
576 if (o->type == OBJ_TAG) {
577 o = deref_tag(o, refname, 0);
578 - packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
578 + if (o)
579 + packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
580 }
581 return 0;
582 }