Skip to content

Commit ca58677

Browse files
authored
Stop bgzf_index_dump_hfile() from writing invalid item counts (#1988)
1 parent acc28ac commit ca58677

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bgzf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,10 +2399,11 @@ int bgzf_index_dump_hfile(BGZF *fp, struct hFILE *idx, const char *name)
23992399
if (bgzf_flush(fp) != 0) return -1;
24002400

24012401
// discard the entry marking the end of the file
2402-
if (fp->mt && fp->idx)
2402+
if (fp->mt && fp->idx && fp->idx->noffs > 0)
24032403
fp->idx->noffs--;
24042404

2405-
if (hwrite_uint64(fp->idx->noffs - 1, idx) < 0) goto fail;
2405+
if (hwrite_uint64(fp->idx->noffs > 0 ? fp->idx->noffs - 1 : 0, idx) < 0)
2406+
goto fail;
24062407
for (i=1; i<fp->idx->noffs; i++)
24072408
{
24082409
if (hwrite_uint64(fp->idx->offs[i].caddr, idx) < 0) goto fail;

0 commit comments

Comments
 (0)