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
@ -19,16 +19,17 @@ static int alloc, used;
|
||||
static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
|
||||
{
|
||||
struct treeent *ent;
|
||||
int len = strlen(path);
|
||||
size_t len = strlen(path);
|
||||
if (strchr(path, '/'))
|
||||
die("path %s contains slash", path);
|
||||
|
||||
ALLOC_GROW(entries, used + 1, alloc);
|
||||
ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
|
||||
FLEX_ALLOC_MEM(ent, name, path, len);
|
||||
ent->mode = mode;
|
||||
ent->len = len;
|
||||
hashcpy(ent->sha1, sha1);
|
||||
memcpy(ent->name, path, len+1);
|
||||
|
||||
ALLOC_GROW(entries, used + 1, alloc);
|
||||
entries[used++] = ent;
|
||||
}
|
||||
|
||||
static int ent_compare(const void *a_, const void *b_)
|
||||
|
Reference in New Issue
Block a user