difftool: handle unmerged files in dir-diff mode
[gitweb.git] / builtin / mktree.c
index a237caacfdfc5905067bb6e3f9ae517b5f83ed17..4282b62c595edd987a87eb23ba679079211e0835 100644 (file)
@@ -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_)