summaryrefslogtreecommitdiff
path: root/bulk-checkin.c
diff options
context:
space:
mode:
authorSun He <sunheehnus@gmail.com>2014-03-03 17:24:29 +0800
committerJunio C Hamano <gitster@pobox.com>2014-03-03 12:15:10 -0800
commit5889271114a25b6750bb6137784ae5a93df22b39 (patch)
tree3f95ef844f90b9c35229cccf4d56c9ac3bcca9d0 /bulk-checkin.c
parent2156a98045f83dd88386b2d4d3241d66bf722ade (diff)
downloadgit-5889271114a25b6750bb6137784ae5a93df22b39.tar.gz
finish_tmp_packfile():use strbuf for pathname constructionsh/finish-tmp-packfile
The old version fixes a maximum length on the buffer, which could be a problem if one is not certain of the length of get_object_directory(). Using strbuf can avoid the protential bug. Helped-by: Michael Haggerty <mhagger@alum.mit.edu> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Sun He <sunheehnus@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bulk-checkin.c')
-rw-r--r--bulk-checkin.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 118c62528b..98e651c284 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -4,6 +4,7 @@
#include "bulk-checkin.h"
#include "csum-file.h"
#include "pack.h"
+#include "strbuf.h"
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
@@ -23,7 +24,7 @@ static struct bulk_checkin_state {
static void finish_bulk_checkin(struct bulk_checkin_state *state)
{
unsigned char sha1[20];
- char packname[PATH_MAX];
+ struct strbuf packname = STRBUF_INIT;
int i;
if (!state->f)
@@ -43,8 +44,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)
close(fd);
}
- sprintf(packname, "%s/pack/pack-", get_object_directory());
- finish_tmp_packfile(packname, state->pack_tmp_name,
+ strbuf_addf(&packname, "%s/pack/pack-", get_object_directory());
+ finish_tmp_packfile(&packname, state->pack_tmp_name,
state->written, state->nr_written,
&state->pack_idx_opts, sha1);
for (i = 0; i < state->nr_written; i++)
@@ -54,6 +55,7 @@ clear_exit:
free(state->written);
memset(state, 0, sizeof(*state));
+ strbuf_release(&packname);
/* Make objects we just wrote available to ourselves */
reprepare_packed_git();
}