comparison 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
comparison
equal deleted inserted replaced
146:5109083b4794 147:535f12e0a5af
107 */ 107 */
108 108
109 int 109 int
110 array_insert(struct array *arr, const void *data, int index) 110 array_insert(struct array *arr, const void *data, int index)
111 { 111 {
112 if (arr->flags & ARRAY_INSERTSAFE)
113 if (index < 0 || index > arr->length)
114 return -1;
115
112 if (index < 0) 116 if (index < 0)
113 return array_push(arr, data); 117 return array_push(arr, data);
114 if (index >= arr->length) 118 if (index >= arr->length)
115 return array_append(arr, data); 119 return array_append(arr, data);
116 120