diff --git a/include/tlibc/collections/Array.h b/include/tlibc/collections/Array.h index 1421ca0..066cbaf 100755 --- a/include/tlibc/collections/Array.h +++ b/include/tlibc/collections/Array.h @@ -14,9 +14,12 @@ typedef struct Array_ { #define Array_construct(DATA, T, COUNT) Array_construct_size(DATA, (COUNT) * sizeof(T)) #define Array_construct_size(DATA, LEN) ((Array_){ .data = (DATA), .size = (LEN) }) -#define Array_alloc(T, COUNT) Array_alloc_size((COUNT) * sizeof(T)) +#define Array_null Array_construct_size(NULL, 0) +#define Array_alloc(T, COUNT) Array_alloc_size((COUNT) * sizeof(T)) static inline Array_ Array_alloc_size(u32 size){ + if(size == 0) + return Array_null; return Array_construct_size(size > 0 ? malloc(size) : NULL, size); } diff --git a/include/tlibc/collections/List.h b/include/tlibc/collections/List.h index b7cd942..6f26e3d 100755 --- a/include/tlibc/collections/List.h +++ b/include/tlibc/collections/List.h @@ -15,6 +15,7 @@ typedef struct List_ { static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 allocated_size) { return (List_){ .data = data_ptr, .size = occupied_size, .allocated_size = allocated_size }; } +#define List_null List_construct_size(NULL, 0, 0) #define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T)) List_ List_alloc_size(u32 initial_size); diff --git a/include/tlibc/errors.h b/include/tlibc/errors.h index 44685e8..59709a2 100755 --- a/include/tlibc/errors.h +++ b/include/tlibc/errors.h @@ -122,7 +122,7 @@ typedef struct Result_ { #define try_stderrcode(CALL) do {\ int r = CALL;\ if(r != 0){\ - Return RESULT_ERROR(strerror(r), false);\ + Return RESULT_ERROR_CODE(LIBC_ERRNO, r, strerror(r), false);\ }\ } while(0) diff --git a/src/collections/List.c b/src/collections/List.c index 5e9640c..d2fa4f2 100755 --- a/src/collections/List.c +++ b/src/collections/List.c @@ -2,7 +2,7 @@ List_ List_alloc_size(u32 initial_size){ if(initial_size == 0) - return List_construct_size(NULL, 0, 0); + return List_null; u32 allocated_size = ALIGN_TO(initial_size, sizeof(void*)); return List_construct_size(malloc(allocated_size), 0, allocated_size); }