Fix some missing allocation checks / length checks
This commit is contained in:
parent
2162b8b580
commit
ce37113f93
3 changed files with 27 additions and 8 deletions
21
src/parser.c
21
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])) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
12
src/value.c
12
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++) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue