Skip to content

Commit c77722b

Browse files
rscharfegitster
authored andcommitted
use get_tagged_oid()
Avoid derefencing ->tagged without checking for NULL by using the convenience wrapper for getting the ID of the tagged object. It die()s when encountering a broken tag instead of segfaulting. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dad3f06 commit c77722b

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
313313
*/
314314
append_name(n, dst);
315315
if (longformat)
316-
append_suffix(0, n->tag ? &n->tag->tagged->oid : oid, dst);
316+
append_suffix(0, n->tag ? get_tagged_oid(n->tag) : oid, dst);
317317
if (suffix)
318318
strbuf_addstr(dst, suffix);
319319
return;

builtin/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
627627
break;
628628
case OBJ_TAG: {
629629
struct tag *t = (struct tag *)o;
630+
struct object_id *oid = get_tagged_oid(t);
630631

631632
if (rev.shown_one)
632633
putchar('\n');
@@ -638,10 +639,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
638639
rev.shown_one = 1;
639640
if (ret)
640641
break;
641-
o = parse_object(the_repository, &t->tagged->oid);
642+
o = parse_object(the_repository, oid);
642643
if (!o)
643644
ret = error(_("could not read object %s"),
644-
oid_to_hex(&t->tagged->oid));
645+
oid_to_hex(oid));
645646
objects[i].item = o;
646647
i--;
647648
break;

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static int check_one_mergetag(struct commit *commit,
421421
if (get_oid(mergetag_data->argv[i], &oid) < 0)
422422
return error(_("not a valid object name: '%s'"),
423423
mergetag_data->argv[i]);
424-
if (oideq(&tag->tagged->oid, &oid))
424+
if (oideq(get_tagged_oid(tag), &oid))
425425
return 0; /* found */
426426
}
427427

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ static int add_promisor_object(const struct object_id *oid,
21392139
oidset_insert(set, &parents->item->object.oid);
21402140
} else if (obj->type == OBJ_TAG) {
21412141
struct tag *tag = (struct tag *) obj;
2142-
oidset_insert(set, &tag->tagged->oid);
2142+
oidset_insert(set, get_tagged_oid(tag));
21432143
}
21442144
return 0;
21452145
}

ref-filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
17661766
* If it is a tag object, see if we use a value that derefs
17671767
* the object, and if we do grab the object it refers to.
17681768
*/
1769-
oi_deref.oid = ((struct tag *)obj)->tagged->oid;
1769+
oi_deref.oid = *get_tagged_oid((struct tag *)obj);
17701770

17711771
/*
17721772
* NEEDSWORK: This derefs tag only once, which
@@ -1997,7 +1997,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
19971997
if (!obj)
19981998
die(_("malformed object at '%s'"), refname);
19991999
if (obj->type == OBJ_TAG)
2000-
tagged_oid = &((struct tag *)obj)->tagged->oid;
2000+
tagged_oid = get_tagged_oid((struct tag *)obj);
20012001
if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
20022002
return tagged_oid;
20032003
return NULL;

0 commit comments

Comments
 (0)