summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-05-24 05:36:23 -0700
committerVicent Martí <vicent@github.com>2013-05-24 05:36:23 -0700
commit4bc67efd7408faaab714478604a0543e568b7564 (patch)
tree36a3edde4517dbad68cefb460b05831a7fb7e59c
parent26ab6284b20a3709adc7641a52250f72df9257aa (diff)
parent43efc4493d72b4666d8fe31b89c3aad97c3ec1a3 (diff)
downloadlibgit2-4bc67efd7408faaab714478604a0543e568b7564.tar.gz
Merge pull request #1605 from ethomson/replace_reuc_fix
Cherry picking REUC fixes
-rw-r--r--src/index.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/index.c b/src/index.c
index ec45a5c0e..d5d9aef48 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1373,8 +1373,9 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
size_t len;
int i;
- /* This gets called multiple times, the vector might already be initialized */
- if (index->reuc._alloc_size == 0 && git_vector_init(&index->reuc, 16, reuc_cmp) < 0)
+ /* If called multiple times, the vector might already be initialized */
+ if (index->reuc._alloc_size == 0 &&
+ git_vector_init(&index->reuc, 16, reuc_cmp) < 0)
return -1;
while (size) {
@@ -1384,12 +1385,9 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
if (size <= len)
return index_error_invalid("reading reuc entries");
- lost = git__malloc(sizeof(git_index_reuc_entry));
+ lost = git__calloc(1, sizeof(git_index_reuc_entry));
GITERR_CHECK_ALLOC(lost);
- if (git_vector_insert(&index->reuc, lost) < 0)
- return -1;
-
/* read NUL-terminated pathname for entry */
lost->path = git__strdup(buffer);
GITERR_CHECK_ALLOC(lost->path);
@@ -1427,6 +1425,10 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
size -= 20;
buffer += 20;
}
+
+ /* entry was read successfully - insert into reuc vector */
+ if (git_vector_insert(&index->reuc, lost) < 0)
+ return -1;
}
/* entries are guaranteed to be sorted on-disk */