Ensure list->_maxSize is correctly updated when memory cannot be reallocated

main
Hammy 3 years ago
parent 13af5aefd6
commit 2e5a5c5b64

@ -50,6 +50,7 @@ int List_append(List *list, int element) {
list->_maxSize *= 2; list->_maxSize *= 2;
int *temp = realloc(list->_array, list->_maxSize * sizeof(int)); int *temp = realloc(list->_array, list->_maxSize * sizeof(int));
if (!temp) { if (!temp) {
list->_maxSize /= 2;
return ERRNO_002; return ERRNO_002;
} }
list->_array = temp; list->_array = temp;

Loading…
Cancel
Save