Skip to content

Commit f3e59fc

Browse files
Avoid NULL pointer dereference (#1154)
If the allocated region is 0 bytes then it's unsafe to dereference it. Fixes #1147.
1 parent fc2e160 commit f3e59fc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ int32_t mm_idx_cal_max_occ(const mm_idx_t *mi, float f)
192192
if (f <= 0.) return INT32_MAX;
193193
for (i = 0; i < 1<<mi->b; ++i)
194194
if (mi->B[i].h) n += kh_size((idxhash_t*)mi->B[i].h);
195+
if (n == 0) return INT32_MAX;
195196
a = (uint32_t*)malloc(n * 4);
196197
for (i = n = 0; i < 1<<mi->b; ++i) {
197198
idxhash_t *h = (idxhash_t*)mi->B[i].h;

0 commit comments

Comments
 (0)