diff --git a/hts.c b/hts.c index c79d92d993..66b8643e80 100644 --- a/hts.c +++ b/hts.c @@ -3077,16 +3077,14 @@ hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, hts_pos_t beg, hts_pos_t free(iter); iter = NULL; } + } else if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL) { + iter->finished = 1; } else { if (beg < 0) beg = 0; if (end < beg) { free(iter); return NULL; } - if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL) { - free(iter); - return NULL; - } k = kh_get(bin, bidx, META_BIN(idx)); if (k != kh_end(bidx)) diff --git a/test/modhdr.expected.vcf b/test/modhdr.expected.vcf new file mode 100644 index 0000000000..bad663c7ed --- /dev/null +++ b/test/modhdr.expected.vcf @@ -0,0 +1,4 @@ +##fileformat=VCFv4.3 +##FILTER= +##contig= +#CHROM POS ID REF ALT QUAL FILTER INFO diff --git a/test/modhdr.vcf.gz b/test/modhdr.vcf.gz new file mode 100644 index 0000000000..f97e06ab3d Binary files /dev/null and b/test/modhdr.vcf.gz differ diff --git a/test/modhdr.vcf.gz.csi b/test/modhdr.vcf.gz.csi new file mode 100644 index 0000000000..61b60e79ae Binary files /dev/null and b/test/modhdr.vcf.gz.csi differ diff --git a/test/test.pl b/test/test.pl index fc6036f60b..c40d58c57b 100755 --- a/test/test.pl +++ b/test/test.pl @@ -947,6 +947,11 @@ sub test_vcf_various cmd => "$$opts{bin}/htsfile -c $$opts{path}/formatmissing.vcf"); test_cmd($opts, %args, out => "vcf_meta_meta.vcf", cmd => "$$opts{bin}/htsfile -c $$opts{path}/vcf_meta_meta.vcf"); + + # VCF file with contig IDX=1, simulating an edited BCF file + # See htslib issue 1534 + test_cmd($opts, %args, out => "modhdr.expected.vcf", + cmd => "$$opts{path}/test_view $$opts{path}/modhdr.vcf.gz chr22:1-2"); } sub write_multiblock_bgzf { diff --git a/test/test_view.c b/test/test_view.c index 416ffe98db..f33c1cdf02 100644 --- a/test/test_view.c +++ b/test/test_view.c @@ -224,7 +224,8 @@ int vcf_loop(int argc, char **argv, int optind, struct opts *opts, htsFile *in, hts_itr_t *iter; if ((iter = bcf_itr_querys(idx, h, argv[i])) == 0) { fprintf(stderr, "[E::%s] fail to parse region '%s'\n", __func__, argv[i]); - continue; + exit_code = 1; + break; } while ((r = bcf_itr_next(in, iter, b)) >= 0) { if (!opts->benchmark && bcf_write1(out, h, b) < 0) {