aboutsummaryrefslogtreecommitdiff
path: root/BumpAlloc.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-04-28 14:28:06 +0300
committerSyndamia <kamen@syndamia.com>2026-05-12 07:08:56 +0300
commita619dd631c367d60a06a28e81fec634c7d827308 (patch)
treefecb09aa088d406df98658b57137a0ac3c19782e /BumpAlloc.c
parent0d249b1d47a7f84cfe5f09ad070d1affd26566da (diff)
downloadfoollib-a619dd631c367d60a06a28e81fec634c7d827308.tar
foollib-a619dd631c367d60a06a28e81fec634c7d827308.tar.gz
foollib-a619dd631c367d60a06a28e81fec634c7d827308.zip
chore: Add safety checks and clean up code style
Diffstat (limited to 'BumpAlloc.c')
-rw-r--r--BumpAlloc.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/BumpAlloc.c b/BumpAlloc.c
index 09af8fa..e162081 100644
--- a/BumpAlloc.c
+++ b/BumpAlloc.c
@@ -14,7 +14,7 @@ top_size(struct BumpAlloc* b) {
return (usize*)(b->memory + b->top);
}
-static int
+static inline int
bump_resizeable(struct BumpAlloc *b, void *ptr) {
if (NULL == b)
return 0;
@@ -48,6 +48,9 @@ bump_free(MemoryManager mm, void **ptr) {
Result
bump_destroy(MemoryManager *mm) {
+ if (NULL == mm)
+ return R_NullArgument;
+
if (NULL == mm->priv)
return R_Uninitialized;
@@ -56,7 +59,7 @@ bump_destroy(MemoryManager *mm) {
if (NULL == b.memory) {
free(mm->priv);
mm->priv = NULL;
- return R_Uninitialized;
+ return R_InvalidArgument;
}
free(b.memory);
@@ -67,13 +70,13 @@ bump_destroy(MemoryManager *mm) {
}
Result
-bump_alloc(MemoryManager mm, void** ptr, usize size) {
- if (NULL == mm.priv)
- return R_Uninitialized;
-
+bump_alloc(MemoryManager mm, void **ptr, usize size) {
if (0 == size || NULL == ptr)
return R_NullArgument;
+ if (NULL == mm.priv)
+ return R_Uninitialized;
+
struct BumpAlloc *b = (struct BumpAlloc*)mm.priv;
if (size + b->top + sizeof(usize) > b->size)