Skip to content

Commit a78c188

Browse files
peffgitster
authored andcommitted
fast-import: simplify allocation in start_packfile
This function allocate a packed_git flex-array, and adds a mysterious 2 bytes to the length of the pack_name field. One is for the trailing NUL, but the other has no purpose. This is probably cargo-culted from add_packed_git, which gets the ".idx" path and needed to allocate enough space to hold the matching ".pack" (though since 48bcc1c, we calculate the size there differently). This site, however, is using the raw path of a tempfile, and does not need the extra byte. We can just replace the allocation with FLEX_ALLOC_STR, which handles the allocation and the NUL for us. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e0b8373 commit a78c188

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

fast-import.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,12 @@ static void start_packfile(void)
865865
{
866866
static char tmp_file[PATH_MAX];
867867
struct packed_git *p;
868-
int namelen;
869868
struct pack_header hdr;
870869
int pack_fd;
871870

872871
pack_fd = odb_mkstemp(tmp_file, sizeof(tmp_file),
873872
"pack/tmp_pack_XXXXXX");
874-
namelen = strlen(tmp_file) + 2;
875-
p = xcalloc(1, sizeof(*p) + namelen);
876-
xsnprintf(p->pack_name, namelen, "%s", tmp_file);
873+
FLEX_ALLOC_STR(p, pack_name, tmp_file);
877874
p->pack_fd = pack_fd;
878875
p->do_not_close = 1;
879876
pack_file = sha1fd(pack_fd, p->pack_name);

0 commit comments

Comments
 (0)