colors

extract colors from pictures
git clone git://git.2f30.org/colors
Log | Files | Refs | README | LICENSE

commit 2a945fc158c1ca8d069e1c074531478c799566dc
parent 2468a471968cb77ba4a6bb9f2c0dc4c8226f85d0
Author: sin <sin@2f30.org>
Date:   Thu, 11 Jun 2015 10:08:11 +0100

Add bounds checking to vector_get()

Diffstat:
Mcolors.c | 3+--
Mvector.c | 2++
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/colors.c b/colors.c @@ -262,8 +262,7 @@ process(void) while (!done) { done = 1; - for (j = 0; j < vector_size(&points); j++) { - p = vector_get(&points, j); + for (j = 0; (p = vector_get(&points, j)); j++) { for (i = 0; i < nclusters; i++) dists[i] = distance(p, &clusters[i].center); diff --git a/vector.c b/vector.c @@ -38,6 +38,8 @@ vector_add(struct vector *v, void *data) void * vector_get(struct vector *v, size_t i) { + if (i >= v->s) + return NULL; return v->d[i].raw; }