Commit 52056db9c1d6cccf30fc2e22d9b391017bef5eea

Vicent Marti 2014-04-06T16:22:29

Merge pull request #2250 from jacquesg/vector-leak Don't lose our elements when calling git_vector_set()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/vector.c b/src/vector.c
index c2c67e6..37ea07f 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -327,8 +327,10 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
 
 int git_vector_set(void **old, git_vector *v, size_t position, void *value)
 {
-	if (git_vector_resize_to(v, position + 1) < 0)
-		return -1;
+	if (position + 1 > v->length) {
+		if (git_vector_resize_to(v, position + 1) < 0)
+			return -1;
+	}
 
 	if (old != NULL)
 		*old = v->contents[position];