*
* Copyright (c) 2021 by Art Cancro
*
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is open source software. Use, duplication, or disclosure
+ * is subject to the terms of the GNU General Public License, version 3.
*/
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);
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.