From d1fc03d6758dcb7ccca3e4255114d85acfad08d4 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Fri, 7 Jul 2023 19:30:39 -0400 Subject: Add malloc wrapper Abort on allocation failure. This is mostly done as a formality, as Linux tends to over-commit memory anyway. In the event of most failures, we won't have a reasonable recovery either. Signed-off-by: Malfurious --- helpers.c | 8 ++++++++ helpers.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/helpers.c b/helpers.c index c93b774..2cd119d 100644 --- a/helpers.c +++ b/helpers.c @@ -1,8 +1,16 @@ +#include #include #include +#include #include "helpers.h" +void *xmalloc(size_t size) { + void *ptr = malloc((size ? size : 1)); + assert(ptr != NULL); + return ptr; +} + void cursinit(void) { setlocale(LC_ALL, ""); initscr(); diff --git a/helpers.h b/helpers.h index 7b85319..e0cd8c5 100644 --- a/helpers.h +++ b/helpers.h @@ -2,6 +2,9 @@ #include #include +#include + +extern void *xmalloc(size_t size); extern void cursinit(void); extern void cursupdate(void); -- cgit v1.2.3