aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-09-17 10:17:16 +0200
committerHimbeer <himbeer@disroot.org>2024-09-17 18:01:03 +0200
commitf03688fa74b9bb3f13a106e61a3d7f2e9e85c8f8 (patch)
treeaec747d5cdd7cfa86d1b58705f70a5b8c0e888ad /src/util.c
parent2f595cce4a25c04052199043e8cc0d0bba7e1ceb (diff)
Add must_malloc helper function
malloc(3) can fail, most likely in out-of-memory situations. This helper terminates the program in such cases instead of permitting assignments of null pointers.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..d34b722
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+
+void *
+must_malloc(size_t size)
+{
+ void *ret = malloc(size);
+ if (ret == NULL) {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_ABNORMAL);
+ }
+}