summaryrefslogtreecommitdiff
path: root/pack-write.c
diff options
context:
space:
mode:
authorSun He <sunheehnus@gmail.com>2014-03-03 09:24:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-03-03 20:15:10 (GMT)
commit5889271114a25b6750bb6137784ae5a93df22b39 (patch)
tree3f95ef844f90b9c35229cccf4d56c9ac3bcca9d0 /pack-write.c
parent2156a98045f83dd88386b2d4d3241d66bf722ade (diff)
downloadgit-5889271114a25b6750bb6137784ae5a93df22b39.zip
git-5889271114a25b6750bb6137784ae5a93df22b39.tar.gz
git-5889271114a25b6750bb6137784ae5a93df22b39.tar.bz2
finish_tmp_packfile():use strbuf for pathname construction
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 'pack-write.c')
-rw-r--r--pack-write.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/pack-write.c b/pack-write.c
index 9b8308b..9ccf804 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -336,7 +336,7 @@ struct sha1file *create_tmp_packfile(char **pack_tmp_name)
return sha1fd(fd, *pack_tmp_name);
}
-void finish_tmp_packfile(char *name_buffer,
+void finish_tmp_packfile(struct strbuf *name_buffer,
const char *pack_tmp_name,
struct pack_idx_entry **written_list,
uint32_t nr_written,
@@ -344,7 +344,7 @@ void finish_tmp_packfile(char *name_buffer,
unsigned char sha1[])
{
const char *idx_tmp_name;
- char *end_of_name_prefix = strrchr(name_buffer, 0);
+ int basename_len = name_buffer->len;
if (adjust_shared_perm(pack_tmp_name))
die_errno("unable to make temporary pack file readable");
@@ -354,17 +354,19 @@ void finish_tmp_packfile(char *name_buffer,
if (adjust_shared_perm(idx_tmp_name))
die_errno("unable to make temporary index file readable");
- sprintf(end_of_name_prefix, "%s.pack", sha1_to_hex(sha1));
- free_pack_by_name(name_buffer);
+ strbuf_addf(name_buffer, "%s.pack", sha1_to_hex(sha1));
+ free_pack_by_name(name_buffer->buf);
- if (rename(pack_tmp_name, name_buffer))
+ if (rename(pack_tmp_name, name_buffer->buf))
die_errno("unable to rename temporary pack file");
- sprintf(end_of_name_prefix, "%s.idx", sha1_to_hex(sha1));
- if (rename(idx_tmp_name, name_buffer))
+ strbuf_setlen(name_buffer, basename_len);
+
+ strbuf_addf(name_buffer, "%s.idx", sha1_to_hex(sha1));
+ if (rename(idx_tmp_name, name_buffer->buf))
die_errno("unable to rename temporary index file");
- *end_of_name_prefix = '\0';
+ strbuf_setlen(name_buffer, basename_len);
free((void *)idx_tmp_name);
}