Skip to content

Commit dad3f06

Browse files
rscharfegitster
authored andcommitted
tag: factor out get_tagged_oid()
Add a function for accessing the ID of the object referenced by a tag safely, i.e. without causing a segfault when encountering a broken tag where ->tagged is NULL. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 745f681 commit dad3f06

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

pack-bitmap.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
709709
else
710710
object_list_insert(object, &wants);
711711

712-
if (!tag->tagged)
713-
die("bad tag");
714-
object = parse_object_or_die(&tag->tagged->oid, NULL);
712+
object = parse_object_or_die(get_tagged_oid(tag), NULL);
715713
}
716714

717715
if (object->flags & UNINTERESTING)

revision.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ static struct commit *handle_commit(struct rev_info *revs,
404404
struct tag *tag = (struct tag *) object;
405405
if (revs->tag_objects && !(flags & UNINTERESTING))
406406
add_pending_object(revs, object, tag->tag);
407-
if (!tag->tagged)
408-
die("bad tag");
409-
object = parse_object(revs->repo, &tag->tagged->oid);
407+
object = parse_object(revs->repo, get_tagged_oid(tag));
410408
if (!object) {
411409
if (revs->ignore_missing_links || (flags & UNINTERESTING))
412410
return NULL;

tag.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,10 @@ int parse_tag(struct tag *item)
212212
free(data);
213213
return ret;
214214
}
215+
216+
struct object_id *get_tagged_oid(struct tag *tag)
217+
{
218+
if (!tag->tagged)
219+
die("bad tag");
220+
return &tag->tagged->oid;
221+
}

tag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ struct object *deref_tag(struct repository *r, struct object *, const char *, in
1919
struct object *deref_tag_noverify(struct object *);
2020
int gpg_verify_tag(const struct object_id *oid,
2121
const char *name_to_report, unsigned flags);
22+
struct object_id *get_tagged_oid(struct tag *tag);
2223

2324
#endif /* TAG_H */

0 commit comments

Comments
 (0)