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:
committed by
Junio C Hamano
parent
3733e69464
commit
96ffc06f72
@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user