log-tree: use FLEX_ARRAY in name_decoration

We are already using the flex-array technique; let's annotate it with our usual FLEX_ARRAY macro. Besides being more readable, this is slightly more efficient on compilers that understand flex-arrays. Note that we need to bump the allocation in add_name_decoration, which did not explicitly add one byte for the NUL terminator of the string we are putting into the flex-array (it did not need to before, because the struct itself was over-allocated by one byte). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 26, 2014 at 06:24 UTC 2e3dfb216991974b60fdb1933eb3331e03383e61
2 files changed +2 -2
commit.h
+1 -1
@@ -30,7 +30,7 @@ extern const char *commit_type;
30 struct name_decoration {
31 struct name_decoration *next;
32 int type;
33 - char name[1];
33 + char name[FLEX_ARRAY];
34 };
35
36 enum decoration_type {
log-tree.c
+1 -1
@@ -77,7 +77,7 @@ int parse_decorate_color_config(const char *var, const int ofs, const char *valu
77 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
78 {
79 int nlen = strlen(name);
80 - struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + nlen);
80 + struct name_decoration *res = xmalloc(sizeof(*res) + nlen + 1);
81 memcpy(res->name, name, nlen + 1);
82 res->type = type;
83 res->next = add_decoration(&name_decoration, obj, res);