correction null toolbox.c

This commit is contained in:
2026-04-13 00:38:39 +02:00
parent 35b04e088e
commit 485d289e95
+13 -3
View File
@@ -5,8 +5,11 @@
#include <stdlib.h>
struct array *sort(struct array *arr, comparator f)
{
if(!arr || !f) return NULL;
void *temp = malloc(arr->elem_size);
if(!temp) return NULL;
if (arr->len > 0) {
for(size_t index1 = 0; index1 < arr->len - 1; index1 ++ ){
@@ -30,7 +33,9 @@ struct array *sort(struct array *arr, comparator f)
}
struct array *map(struct array *arr, size_t output_size, mapper f)
{
{
if(!arr || !f)return NULL;
void *data = calloc(arr->len, output_size);
if(!data) return NULL;
@@ -52,6 +57,8 @@ struct array *map(struct array *arr, size_t output_size, mapper f)
struct array *filter(struct array *arr, predicate f)
{
if(!arr || !f) return NULL;
size_t index = 0;
int flon = 0;
while(index != arr->len){
@@ -66,8 +73,8 @@ struct array *filter(struct array *arr, predicate f)
index = 0;
void *data1 = calloc(flon, arr->elem_size);
if(!data1 && flon > 0) return NULL;
size_t index2 = 0;
while(index != arr->len){
void *cur = arr->data + index * arr->elem_size;
@@ -88,6 +95,8 @@ struct array *filter(struct array *arr, predicate f)
void *reduce(struct array *arr, void *start_value, reducer f)
{
if(!arr || !start_value || !f) return NULL;
void *rslt = start_value;
size_t index = 0;
@@ -103,6 +112,7 @@ void *reduce(struct array *arr, void *start_value, reducer f)
void foreach(struct array *arr, acceptor f)
{
if(!arr || !f) return;
// arr.data est un array de x valeurs
size_t index = 0;