- bam_fetch(in->x.bam, idx, tid, beg, end, out, view_func); // fetch alignments
+ // fetch alignments
+ if (bam_fetch(in->x.bam, idx, tid, beg, end, out, view_func) < 0) {
+ fprintf(stderr, "[main_samview] retrieval of region \"%s\" failed due to truncated file or corrupt BAM index file\n", argv[i]);
+ ret = 1;
+ break;
+ }