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>
This commit is contained in:
Jeff King
2016-02-22 17:44:32 -05:00
committed by Junio C Hamano
parent 3733e69464
commit 96ffc06f72
17 changed files with 35 additions and 82 deletions

View 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;