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
6
help.c
6
help.c
@ -11,11 +11,9 @@
|
||||
|
||||
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
|
||||
{
|
||||
struct cmdname *ent = xmalloc(sizeof(*ent) + len + 1);
|
||||
|
||||
struct cmdname *ent;
|
||||
FLEX_ALLOC_MEM(ent, name, name, len);
|
||||
ent->len = len;
|
||||
memcpy(ent->name, name, len);
|
||||
ent->name[len] = 0;
|
||||
|
||||
ALLOC_GROW(cmds->names, cmds->cnt + 1, cmds->alloc);
|
||||
cmds->names[cmds->cnt++] = ent;
|
||||
|
||||
Reference in New Issue
Block a user