summaryrefslogtreecommitdiff
path: root/src/pack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-06-07 10:20:44 +0200
committerPatrick Steinhardt <ps@pks.im>2017-06-08 11:58:23 +0200
commita693b8734941889bc9a4c31752d317658162246a (patch)
tree1d9a188fb5ae048209759036963e0eff48b93681 /src/pack.c
parent4796c916d376af528d8bbf07e8a5e176da6ee928 (diff)
downloadlibgit2-a693b8734941889bc9a4c31752d317658162246a.tar.gz
buffer: use `git_buf_init` with length
The `git_buf_init` function has an optional length parameter, which will cause the buffer to be initialized and allocated in one step. This can be used instead of static initialization with `GIT_BUF_INIT` followed by a `git_buf_grow`. This patch does so for two functions where it is applicable.
Diffstat (limited to 'src/pack.c')
-rw-r--r--src/pack.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pack.c b/src/pack.c
index d24c13815..f8d0dc9ac 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -312,7 +312,7 @@ static int pack_index_open(struct git_pack_file *p)
{
int error = 0;
size_t name_len;
- git_buf idx_name = GIT_BUF_INIT;
+ git_buf idx_name;
if (p->index_version > -1)
return 0;
@@ -320,10 +320,13 @@ static int pack_index_open(struct git_pack_file *p)
name_len = strlen(p->pack_name);
assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
- git_buf_grow(&idx_name, name_len);
+ if (git_buf_init(&idx_name, name_len) < 0)
+ return -1;
+
git_buf_put(&idx_name, p->pack_name, name_len - strlen(".pack"));
git_buf_puts(&idx_name, ".idx");
if (git_buf_oom(&idx_name)) {
+ git_buf_free(&idx_name);
return -1;
}