Commit f47db3c799b4f6b63ee8021e0c93d00d5f125c9a

Patrick Steinhardt 2017-02-02T16:02:57

vector: do not reverse a vector if it is empty The code reversing a vector initially determines the rear-pointer by simply subtracting 1 from the vector's length. Obviously, this fails if the vector is empty, in which case we have an integer overflow. Fix the issue by returning early if the vector is empty.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/vector.c b/src/vector.c
index baec803..620a1f5 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -406,6 +406,9 @@ void git_vector_reverse(git_vector *v)
 {
 	size_t a, b;
 
+	if (v->length == 0)
+		return;
+
 	a = 0;
 	b = v->length - 1;