comparison array.c @ 10:da47652b60c5

Fix security issue
author David Demelier <markand@malikania.fr>
date Wed, 07 Sep 2011 20:31:41 +0200
parents bf25ed2cf42a
children cbfe95c9f7b7
comparison
equal deleted inserted replaced
9:bf25ed2cf42a 10:da47652b60c5
62 array_push(struct array *arr, const void *data) 62 array_push(struct array *arr, const void *data)
63 { 63 {
64 if (array_grow(arr) < 0) 64 if (array_grow(arr) < 0)
65 return -1; 65 return -1;
66 66
67 memmove(&arr->data[SIZE(1)], arr->data, SIZE(arr->length++)); 67 memmove(&arr->data[arr->unit], &arr->data[0], SIZE(arr->length++));
68 memcpy(&arr->data[0], data, arr->unit); 68 memcpy(&arr->data[0], data, arr->unit);
69 69
70 return 0; 70 return 0;
71 } 71 }
72 72
244 if (arr->flags & ARRAY_AUTO) { 244 if (arr->flags & ARRAY_AUTO) {
245 if (!(arr->data = realloc(arr->data, arr->size + 245 if (!(arr->data = realloc(arr->data, arr->size +
246 SIZE(arr->bsize)))) 246 SIZE(arr->bsize))))
247 return -1; 247 return -1;
248 248
249 arr->size += arr->bsize; 249 arr->size += SIZE(arr->bsize);
250 } else 250 } else
251 return ((arr->size / arr->unit) <= arr->length) ? -1 : 0; 251 return ((arr->size / arr->unit) <= arr->length) ? -1 : 0;
252 252
253 return 0; 253 return 0;
254 } 254 }