avoid pointer arithmetic involving NULL in FLEX_ALLOC_MEM
[gitweb.git] / ref-filter.c
index f097176ed93229fe75533e21dc60e0bbc5a4e7ef..9ccfc51ceadb79fdf376da79741c9693db8513bb 100644 (file)
@@ -1255,10 +1255,8 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
                                                 const unsigned char *objectname,
                                                 int flag)
 {
-       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';
+       struct ref_array_item *ref;
+       FLEX_ALLOC_STR(ref, refname, refname);
        hashcpy(ref->objectname, objectname);
        ref->flag = flag;