summaryrefslogtreecommitdiff
path: root/src/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/vector.c b/src/vector.c
index b12fa942d..aac4863d4 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -50,22 +50,24 @@ int git_vector_size_hint(git_vector *v, size_t size_hint)
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
{
- size_t bytes;
-
assert(v && src);
- GITERR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *));
-
- v->_alloc_size = src->length;
+ v->_alloc_size = 0;
+ v->contents = NULL;
v->_cmp = cmp ? cmp : src->_cmp;
v->length = src->length;
v->flags = src->flags;
if (cmp != src->_cmp)
git_vector_set_sorted(v, 0);
- v->contents = git__malloc(bytes);
- GITERR_CHECK_ALLOC(v->contents);
- memcpy(v->contents, src->contents, bytes);
+ if (src->length) {
+ size_t bytes;
+ GITERR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *));
+ v->contents = git__malloc(bytes);
+ GITERR_CHECK_ALLOC(v->contents);
+ v->_alloc_size = src->length;
+ memcpy(v->contents, src->contents, bytes);
+ }
return 0;
}