Оновити 'cv4/list_ops.c'
This commit is contained in:
parent
6065f55723
commit
11393048bb
@ -5,17 +5,16 @@
|
||||
#include <string.h>
|
||||
|
||||
list_t *new_list(size_t length, list_element_t elements[]) {
|
||||
list_t *list = malloc(sizeof(list_t));
|
||||
list_t *list = malloc(sizeof(list_t) + length * sizeof(list_element_t));
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
list->elements = malloc(length * sizeof(list_element_t));
|
||||
if (!list->elements) {
|
||||
free(list);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->length = length;
|
||||
memcpy(list->elements, elements, length * sizeof(list_element_t));
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
list->elements[i] = elements[i];
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user