提交 1958a6eb 编写于 作者: K Karthik Nayak 提交者: Junio C Hamano

ref-filter: make 'ref_array_item' use a FLEX_ARRAY for refname

This would remove the need of using a pointer to store refname.
Mentored-by: NChristian Couder <christian.couder@gmail.com>
Mentored-by: NMatthieu Moy <matthieu.moy@grenoble-inp.fr>
Signed-off-by: NKarthik Nayak <karthik.188@gmail.com>
Reviewed-by: NMatthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 14de7fba
......@@ -847,8 +847,10 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
const unsigned char *objectname,
int flag)
{
struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item));
ref->refname = xstrdup(refname);
size_t len = strlen(refname);
struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item) + len + 1);
memcpy(ref->refname, refname, len);
ref->refname[len] = '\0';
hashcpy(ref->objectname, objectname);
ref->flag = flag;
......@@ -889,7 +891,6 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
static void free_array_item(struct ref_array_item *item)
{
free((char *)item->symref);
free(item->refname);
free(item);
}
......
......@@ -32,7 +32,7 @@ struct ref_array_item {
int flag;
const char *symref;
struct atom_value *value;
char *refname;
char refname[FLEX_ARRAY];
};
struct ref_array {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册