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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Sep 5, 2019 at 21:59 UTC
c77722b3ea42a87381915f1203648a5f5d86c1ff
5 files changed
+8
-7
builtin/describe.c
+1
-1
@@ -313,7 +313,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
313
*/
314
append_name(n, dst);
315
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);
317
if (suffix)
318
strbuf_addstr(dst, suffix);
319
return;
builtin/log.c
+3
-2
@@ -627,6 +627,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
627
break;
628
case OBJ_TAG: {
629
struct tag *t = (struct tag *)o;
630
+ struct object_id *oid = get_tagged_oid(t);
631
632
if (rev.shown_one)
633
putchar('\n');
@@ -638,10 +639,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
639
rev.shown_one = 1;
640
if (ret)
641
break;
641
- o = parse_object(the_repository, &t->tagged->oid);
642
+ o = parse_object(the_repository, oid);
643
if (!o)
644
ret = error(_("could not read object %s"),
644
- oid_to_hex(&t->tagged->oid));
645
+ oid_to_hex(oid));
646
objects[i].item = o;
647
i--;
648
break;
builtin/replace.c
+1
-1
@@ -421,7 +421,7 @@ static int check_one_mergetag(struct commit *commit,
421
if (get_oid(mergetag_data->argv[i], &oid) < 0)
422
return error(_("not a valid object name: '%s'"),
423
mergetag_data->argv[i]);
424
- if (oideq(&tag->tagged->oid, &oid))
424
+ if (oideq(get_tagged_oid(tag), &oid))
425
return 0; /* found */
426
}
427
packfile.c
+1
-1
@@ -2139,7 +2139,7 @@ static int add_promisor_object(const struct object_id *oid,
2139
oidset_insert(set, &parents->item->object.oid);
2140
} else if (obj->type == OBJ_TAG) {
2141
struct tag *tag = (struct tag *) obj;
2142
- oidset_insert(set, &tag->tagged->oid);
2142
+ oidset_insert(set, get_tagged_oid(tag));
2143
}
2144
return 0;
2145
}
ref-filter.c
+2
-2
@@ -1766,7 +1766,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
1766
* If it is a tag object, see if we use a value that derefs
1767
* the object, and if we do grab the object it refers to.
1768
*/
1769
- oi_deref.oid = ((struct tag *)obj)->tagged->oid;
1769
+ oi_deref.oid = *get_tagged_oid((struct tag *)obj);
1770
1771
/*
1772
* NEEDSWORK: This derefs tag only once, which
@@ -1997,7 +1997,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
1997
if (!obj)
1998
die(_("malformed object at '%s'"), refname);
1999
if (obj->type == OBJ_TAG)
2000
- tagged_oid = &((struct tag *)obj)->tagged->oid;
2000
+ tagged_oid = get_tagged_oid((struct tag *)obj);
2001
if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
2002
return tagged_oid;
2003
return NULL;