Skip to content

Commit

Permalink
Avoid NULL pointer dereference (#1154)
Browse files Browse the repository at this point in the history
If the allocated region is 0 bytes then it's unsafe to dereference it.

Fixes #1147.
  • Loading branch information
blawrence-ont committed Jan 24, 2024
1 parent fc2e160 commit f3e59fc
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<<mi->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<<mi->b; ++i) {
idxhash_t *h = (idxhash_t*)mi->B[i].h;
Expand Down

0 comments on commit f3e59fc

Please sign in to comment.