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
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user