diff array.c @ 147:535f12e0a5af

Add a flag to prevent insertions at out of bounds
author David Demelier <markand@malikania.fr>
date Fri, 11 May 2012 20:06:41 +0200
parents e3cf5ac9a5aa
children 94847374833b
line wrap: on
line diff
--- a/array.c	Fri May 11 19:06:56 2012 +0200
+++ b/array.c	Fri May 11 20:06:41 2012 +0200
@@ -109,6 +109,10 @@
 int
 array_insert(struct array *arr, const void *data, int index)
 {
+	if (arr->flags & ARRAY_INSERTSAFE)
+		if (index < 0 || index > arr->length)
+			return -1;
+
 	if (index < 0)
 		return array_push(arr, data);
 	if (index >= arr->length)