diff options
Diffstat (limited to 'source/lib/util.c')
-rw-r--r-- | source/lib/util.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/lib/util.c b/source/lib/util.c index f49af133adb..07d99b8769c 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -921,6 +921,9 @@ BOOL yesno(char *p) void *malloc_(size_t size) { + if (size == 0) { + return NULL; + } #undef malloc return malloc(size); #define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY @@ -932,6 +935,9 @@ void *malloc_(size_t size) static void *calloc_(size_t count, size_t size) { + if (size == 0 || count == 0) { + return NULL; + } #undef calloc return calloc(count, size); #define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY @@ -960,6 +966,9 @@ void *malloc_array(size_t el_size, unsigned int count) return NULL; } + if (el_size == 0 || count == 0) { + return NULL; + } #if defined(PARANOID_MALLOC_CHECKER) return malloc_(el_size*count); #else @@ -989,6 +998,9 @@ void *calloc_array(size_t size, size_t nmemb) if (nmemb >= MAX_ALLOC_SIZE/size) { return NULL; } + if (size == 0 || nmemb == 0) { + return NULL; + } #if defined(PARANOID_MALLOC_CHECKER) return calloc_(nmemb, size); #else |