Skip to content

Commit 9c78952

Browse files
committed
Stop bgzf_index_dump_hfile() from writing invalid item counts (samtools#1988)
(cherry picked from commit ca58677)
1 parent 2a813b0 commit 9c78952

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

bgzf.c

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

23942394
// discard the entry marking the end of the file
2395-
if (fp->mt && fp->idx)
2395+
if (fp->mt && fp->idx && fp->idx->noffs > 0)
23962396
fp->idx->noffs--;
23972397

2398-
if (hwrite_uint64(fp->idx->noffs - 1, idx) < 0) goto fail;
2398+
if (hwrite_uint64(fp->idx->noffs > 0 ? fp->idx->noffs - 1 : 0, idx) < 0)
2399+
goto fail;
23992400
for (i=1; i<fp->idx->noffs; i++)
24002401
{
24012402
if (hwrite_uint64(fp->idx->offs[i].caddr, idx) < 0) goto fail;

0 commit comments

Comments
 (0)