diff --git a/src/parser.c b/src/parser.c index a67aa62..7f5230b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1311,7 +1311,18 @@ fragment_to_assignable_inner( case FRAG_LIST: out->type = APFL_EXPR_ASSIGNABLE_LIST; out->list.len = 0; - out->list.items = ALLOC_LIST(struct apfl_expr_assignable_list_item, fragment->list.len); + + if (fragment->list.len == 0) { + return true; + } + + if ((out->list.items = ALLOC_LIST( + struct apfl_expr_assignable_list_item, + fragment->list.len + )) == NULL) { + p->error = apfl_error_simple(APFL_ERR_MALLOC_FAILED); + goto error; + } bool expand_ok = true; for (size_t i = 0; i < fragment->list.len; i++) { @@ -1449,7 +1460,13 @@ fragments_to_call( return true; } - out->call.arguments.items = ALLOC_LIST(struct apfl_expr_list_item, (fragments.len - 1)); + if ((out->call.arguments.items = ALLOC_LIST( + struct apfl_expr_list_item, + (fragments.len - 1) + )) == NULL) { + p->error = apfl_error_simple(APFL_ERR_MALLOC_FAILED); + goto error; + } for (size_t i = 1; i < fragments.len; i++) { if (!fragment_to_list_item(p, fragment_move(&fragments.children[i]), &out->call.arguments.items[i-1])) { diff --git a/src/test.h b/src/test.h index 33a4e45..5942841 100644 --- a/src/test.h +++ b/src/test.h @@ -79,7 +79,7 @@ test_run_test(struct testdef test) char* prefix = malloc(TESTPREFIXSIZE); testctx t = malloc(sizeof(struct testctx_struct)); jmp_buf* here = malloc(sizeof(jmp_buf)); - if(prefix == NULL || t == NULL) { + if(prefix == NULL || t == NULL || here == NULL) { fprintf(stderr, "Could not execute test '%s': could not allocate memory.\n", test.name); free(t); free(prefix); diff --git a/src/value.c b/src/value.c index 8d19ae9..6a9f1d7 100644 --- a/src/value.c +++ b/src/value.c @@ -361,11 +361,13 @@ apfl_editable_list_new_from_list(apfl_list list) elist->len = list->len; elist->cap = list->len; } else { - // We fisrt need to create a shallow copy of the elements - if ((elist->items = ALLOC_LIST(struct apfl_value, list->len)) == NULL) { - apfl_list_unref(list); - free(elist); - return NULL; + // We first need to create a shallow copy of the elements + if (list->len != 0) { + if ((elist->items = ALLOC_LIST(struct apfl_value, list->len)) == NULL) { + apfl_list_unref(list); + free(elist); + return NULL; + } } for (size_t i = 0; i < list->len; i++) {