Skip to content

Commit fdac1d4

Browse files
committed
Make empty region list result in empty VCF
don't segfault Fixes #2250
1 parent 4cc4f0e commit fdac1d4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mpileup.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,12 @@ static int mpileup(mplp_conf_t *conf)
652652
}
653653
}
654654
nregs = regidx_nregs(conf->reg);
655-
conf->reg_itr = regitr_init(conf->reg);
656-
regitr_loop(conf->reg_itr); // region iterator now positioned at the first region
655+
if ( nregs )
656+
{
657+
// the regions list can be empty, see #2250
658+
conf->reg_itr = regitr_init(conf->reg);
659+
regitr_loop(conf->reg_itr); // region iterator now positioned at the first region
660+
}
657661
}
658662

659663
// read the header of each file in the list and initialize data
@@ -699,7 +703,7 @@ static int mpileup(mplp_conf_t *conf)
699703
i--;
700704
continue;
701705
}
702-
if (conf->reg) {
706+
if (conf->reg && nregs) {
703707
hts_idx_t *idx = sam_index_load(conf->mplp_data[i]->fp, conf->files[i]);
704708
if (idx == NULL) {
705709
fprintf(stderr, "[%s] fail to load index for %s\n", __func__, conf->files[i]);
@@ -972,7 +976,7 @@ static int mpileup(mplp_conf_t *conf)
972976
}
973977
while ( regitr_loop(conf->reg_itr) );
974978
}
975-
else
979+
else if ( !conf->reg )
976980
ret = mpileup_reg(conf,0,UINT32_MAX);
977981
if ( ret<0 )
978982
{

0 commit comments

Comments
 (0)