From baeb51ad381d1080e903d2ae4fcd81270ab7f931 Mon Sep 17 00:00:00 2001 From: neheb Date: Sun, 1 Oct 2017 17:46:59 -0700 Subject: [PATCH] Adjust hcmalloc to be the same as calloc calloc is almost equivalent to malloc + memset(0) except that it's faster with big allocations because of OS trickery. It also protects against integer overflow and throws a null pointer on overflow whereas malloc does not. --- src/memory.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/memory.c b/src/memory.c index 1626a3acf..86fe44f6d 100644 --- a/src/memory.c +++ b/src/memory.c @@ -23,16 +23,8 @@ void *hccalloc (const size_t nmemb, const size_t sz) void *hcmalloc (const size_t sz) { - void *p = malloc (sz); - - if (p == NULL) - { - fprintf (stderr, "%s\n", MSG_ENOMEM); - - return (NULL); - } - - memset (p, 0, sz); + //calloc is faster than malloc with big allocations, so just use that. + void *p = hccalloc (sz, 1); return (p); }