commit 3921fa36bd9f094175b9a399bc2dfc6ee230325d
parent 322bdbc251ccb21e967c75ee1b88ce152fc99982
Author: Louis Burda <quent.burda@gmail.com>
Date: Fri, 17 Mar 2023 19:22:11 +0100
Only positive return values
Diffstat:
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/allocator.h b/include/allocator.h
@@ -1,4 +1,4 @@
-#include <stdlib.h>
+#include <stddef.h>
struct allocator {
int (*alloc)(void **p, size_t size);
diff --git a/src/allocator.c b/src/allocator.c
@@ -29,13 +29,15 @@ stdlib_stack_alloc(void **p, size_t size)
{
*p = alloca(size);
- return *p ? 0 : 1;
+ return *p ? 0 : ENOMEM;
}
int
stdlib_stack_realloc(void **p, size_t size)
{
- return 1;
+ *p = NULL;
+
+ return ENOTSUP;
}
int
@@ -49,7 +51,7 @@ stdlib_heap_alloc(void **p, size_t size)
{
*p = malloc(size);
- return *p ? 0 : -errno;
+ return *p ? 0 : errno;
}
int
@@ -58,7 +60,7 @@ stdlib_heap_realloc(void **p, size_t size)
void *np;
np = realloc(*p, size);
- if (!np) return -errno;
+ if (!np) return errno;
*p = np;
return 0;