summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2016-02-22 17:44:32 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commit96ffc06f72f693d80f05059a1f0e5ca9007d5f1b (patch)
tree8f4587b3132a422757280f3d4f7bc302230efd7c /ref-filter.c
parentuse xmallocz to avoid size arithmetic (diff)
downloadtgif-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.tar.xz
convert trivial cases to FLEX_ARRAY macros
Using FLEX_ARRAY macros reduces the amount of manual computation size we have to do. It also ensures we don't overflow size_t, and it makes sure we write the same number of bytes that we allocated. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/ref-filter.c b/ref-filter.c
index f097176ed9..9ccfc51cea 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -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;