diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-12 18:55:32 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-12 18:55:32 -0500 |
commit | 7420a5126f78947e9c5a11e606d59f2ed6391079 (patch) | |
tree | e4f9915e3cee22915556689673d4b1327f0c1f4e /err.c | |
parent | 87c40c71774648edfd8234ec3d8f51411845dd7f (diff) |
...
Diffstat (limited to 'err.c')
-rw-r--r-- | err.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -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"); |