From 9bbfa7d2cd5b46f07052dfb2212d792cb6f2641d Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 3 Dec 2024 00:04:40 +0000 Subject: Some general reworking, error handling --- lib.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 83f3516..4f79345 100644 --- a/lib.c +++ b/lib.c @@ -33,6 +33,14 @@ char *fread_all(FILE *fp) size_t used, available; } buffer = {calloc(CHUNK_SIZE, sizeof(*buffer.data)), 0, CHUNK_SIZE}; + if (!buffer.data) + { + print_error( + "[internal]", 0, 0, + "ERROR: Out of Memory (could not allocate buffer in fread_all)"); + return NULL; + } + size_t acc = 0, bytes_read = 0; while ((bytes_read = fread(buffer.data + acc, sizeof(*buffer.data), CHUNK_SIZE, fp)) != 0) -- cgit v1.2.3-13-gbd6f