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

@ -77,9 +77,8 @@ int parse_decorate_color_config(const char *var, const char *slot_name, const ch
void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
{
int nlen = strlen(name);
struct name_decoration *res = xmalloc(sizeof(*res) + nlen + 1);
memcpy(res->name, name, nlen + 1);
struct name_decoration *res;
FLEX_ALLOC_STR(res, name, name);
res->type = type;
res->next = add_decoration(&name_decoration, obj, res);
}