Prevent alloc errors from crashing

Resolves #76
This commit is contained in:
Calvin Lee 2017-08-15 07:56:47 +02:00
parent 5ca88af557
commit 5cc7342606
13 changed files with 109 additions and 13 deletions

View file

@ -6,9 +6,16 @@
list_t *list_create(void) {
list_t *list = malloc(sizeof(list_t));
if (!list) {
return NULL;
}
list->capacity = 10;
list->length = 0;
list->items = malloc(sizeof(void*) * list->capacity);
if (!list->items) {
free(list);
return NULL;
}
return list;
}