From 8a7f330c37cb679afb34b2387d452c9d97fae375 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 19 Oct 2017 11:55:48 +0000 Subject: [PATCH] Use safe_calloc to initialize memory, simplify size_t overflow check --- hcache/lmdb.c | 4 +--- lib/memory.c | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hcache/lmdb.c b/hcache/lmdb.c index f0aa0cd50..435daf88a 100644 --- a/hcache/lmdb.c +++ b/hcache/lmdb.c @@ -108,9 +108,7 @@ static void *hcache_lmdb_open(const char *path) { int rc; - struct HcacheLmdbCtx *ctx = safe_malloc(sizeof(struct HcacheLmdbCtx)); - ctx->txn = NULL; - ctx->db = 0; + struct HcacheLmdbCtx *ctx = safe_calloc(1, sizeof(struct HcacheLmdbCtx)); rc = mdb_env_create(&ctx->env); if (rc != MDB_SUCCESS) diff --git a/lib/memory.c b/lib/memory.c index 89e7a6249..6e98e59f2 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -37,6 +37,7 @@ */ #include "config.h" +#include #include #include #include "memory.h" @@ -61,7 +62,7 @@ void *safe_calloc(size_t nmemb, size_t size) if (!nmemb || !size) return NULL; - if (((size_t) -1) / nmemb <= size) + if (nmemb > (SIZE_MAX / size)) { mutt_error(_("Integer overflow -- can't allocate memory!")); sleep(1); -- 2.40.0