diff options
author | Himbeer <himbeer@disroot.org> | 2024-09-17 17:59:48 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-09-17 18:01:10 +0200 |
commit | 1ec909c55c48c21279a080050ec24ec5f91cd3f9 (patch) | |
tree | 3a026a5149471ad59a26b5e29f850541993248ce /src | |
parent | fa3aa50a43476a7277931adbc3d2fd3c4e7cf671 (diff) |
Add OOM-safe must_calloc and must_realloc helper functions
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -11,3 +11,25 @@ must_malloc(size_t size) exit(EXIT_ABNORMAL); } } + +void * +must_calloc(size_t nmemb, size_t size) +{ + void *ret = calloc(nmemb, size); + if (ret == NULL) { + fprintf(stderr, "out of memory\n"); + exit(EXIT_ABNORMAL); + } + return ret; +} + +void * +must_realloc(void *ptr, size_t size) +{ + void *ret = realloc(ptr, size); + if (ret == NULL) { + fprintf(stderr, "out of memory\n"); + exit(EXIT_ABNORMAL); + } + return ret; +} |