From 886b0cb22194d1b7f4b89d8e40811fa332f43f38 Mon Sep 17 00:00:00 2001 From: Ben Lawrence Date: Wed, 24 Jan 2024 17:20:27 +0000 Subject: [PATCH] Avoid NULL pointer dereference If the allocated region is 0 bytes then it's unsafe to dereference it. Fixes #1147. --- index.c | 1 + 1 file changed, 1 insertion(+) diff --git a/index.c b/index.c index 0d8a2ae0..cd8b40e4 100644 --- a/index.c +++ b/index.c @@ -192,6 +192,7 @@ int32_t mm_idx_cal_max_occ(const mm_idx_t *mi, float f) if (f <= 0.) return INT32_MAX; for (i = 0; i < 1<b; ++i) if (mi->B[i].h) n += kh_size((idxhash_t*)mi->B[i].h); + if (n == 0) return INT32_MAX; a = (uint32_t*)malloc(n * 4); for (i = n = 0; i < 1<b; ++i) { idxhash_t *h = (idxhash_t*)mi->B[i].h;