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
@ -79,11 +79,9 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
|
||||
ALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc);
|
||||
it->subtree_nr++;
|
||||
|
||||
down = xmalloc(sizeof(*down) + pathlen + 1);
|
||||
FLEX_ALLOC_MEM(down, name, path, pathlen);
|
||||
down->cache_tree = NULL;
|
||||
down->namelen = pathlen;
|
||||
memcpy(down->name, path, pathlen);
|
||||
down->name[pathlen] = 0;
|
||||
|
||||
if (pos < it->subtree_nr)
|
||||
memmove(it->down + pos + 1,
|
||||
|
||||
Reference in New Issue
Block a user