X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=libcitadel%2Flib%2Farray.c;h=1adc1fde8f39f078464b3fdbb486e4930028bfd1;hb=24f7a7da2a52df3e90dbdfd310fc1f2780cd3caf;hp=a8adb292d84ba950fbfabd59a3146f97637622ee;hpb=1144dcb5c82e4360bc9dfd59d3125914ef5a4b6e;p=citadel.git diff --git a/libcitadel/lib/array.c b/libcitadel/lib/array.c index a8adb292d..1adc1fde8 100644 --- a/libcitadel/lib/array.c +++ b/libcitadel/lib/array.c @@ -61,12 +61,18 @@ void array_append(Array *arr, void *new_element) { arr->num_alloc = 1; arr->num_elements = 0; arr->the_elements = malloc(arr->element_size * arr->num_alloc); + if (arr->the_elements == NULL) { + abort(); + } } ++arr->num_elements; if (arr->num_elements > arr->num_alloc) { arr->num_alloc = arr->num_alloc * 2; // whenever we exceed the buffer size, we double it. arr->the_elements = realloc(arr->the_elements, (arr->element_size * arr->num_alloc)); + if (arr->the_elements == NULL) { + abort(); + } } memcpy((arr->the_elements + ( (arr->num_elements-1) * arr->element_size )), new_element, arr->element_size); @@ -107,6 +113,10 @@ void array_delete_element_at(Array *arr, int index) { return; } + if (index < 0) { // If the supplied index is invalid, return quietly. + return; + } + --arr->num_elements; if (index == arr->num_elements) { // If we deleted the element at the end, there's no more to be done.