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
@ -382,11 +382,9 @@ static int collect_reflog(const char *ref, const struct object_id *oid, int unus
|
||||
{
|
||||
struct collected_reflog *e;
|
||||
struct collect_reflog_cb *cb = cb_data;
|
||||
size_t namelen = strlen(ref);
|
||||
|
||||
e = xmalloc(sizeof(*e) + namelen + 1);
|
||||
FLEX_ALLOC_STR(e, reflog, ref);
|
||||
hashcpy(e->sha1, oid->hash);
|
||||
memcpy(e->reflog, ref, namelen + 1);
|
||||
ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
|
||||
cb->e[cb->nr++] = e;
|
||||
return 0;
|
||||
@ -411,8 +409,7 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
|
||||
ent->pattern[len] == '\0')
|
||||
return ent;
|
||||
|
||||
ent = xcalloc(1, sizeof(*ent) + len + 1);
|
||||
memcpy(ent->pattern, pattern, len);
|
||||
FLEX_ALLOC_MEM(ent, pattern, pattern, len);
|
||||
*reflog_expire_cfg_tail = ent;
|
||||
reflog_expire_cfg_tail = &(ent->next);
|
||||
return ent;
|
||||
|
Reference in New Issue
Block a user