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

@ -2132,16 +2132,13 @@ static int one_local_ref(const char *refname, const struct object_id *oid,
{
struct ref ***local_tail = cb_data;
struct ref *ref;
int len;
/* we already know it starts with refs/ to get here */
if (check_refname_format(refname + 5, 0))
return 0;
len = strlen(refname) + 1;
ref = xcalloc(1, sizeof(*ref) + len);
ref = alloc_ref(refname);
oidcpy(&ref->new_oid, oid);
memcpy(ref->name, refname, len);
**local_tail = ref;
*local_tail = &ref->next;
return 0;