summaryrefslogtreecommitdiff
path: root/err.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-12-12 18:55:32 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-12-12 18:55:32 -0500
commit7420a5126f78947e9c5a11e606d59f2ed6391079 (patch)
treee4f9915e3cee22915556689673d4b1327f0c1f4e /err.c
parent87c40c71774648edfd8234ec3d8f51411845dd7f (diff)
...
Diffstat (limited to 'err.c')
-rw-r--r--err.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/err.c b/err.c
index fdebbfc..11a4863 100644
--- a/err.c
+++ b/err.c
@@ -158,6 +158,7 @@ static void warn_print(Location where, const char *fmt, ...) {
}
static void *err_malloc(size_t size) {
+ if (size == 0) return NULL;
void *ret = malloc(size);
if (!ret) {
fprintf(stderr, "Error: Out of memory.\n");
@@ -167,6 +168,7 @@ static void *err_malloc(size_t size) {
}
static void *err_calloc(size_t n, size_t size) {
+ if (n == 0 || size == 0) return NULL;
void *ret = calloc(n, size);
if (!ret) {
fprintf(stderr, "Error: Out of memory.\n");
@@ -176,6 +178,10 @@ static void *err_calloc(size_t n, size_t size) {
}
static void *err_realloc(void *data, size_t new_size) {
+ if (new_size == 0) {
+ free(data);
+ return NULL;
+ }
void *ret = realloc(data, new_size);
if (!ret) {
fprintf(stderr, "Error: Out of memory.\n");