From 632560e7c395773abba25abac50d7efaaa84e5fe Mon Sep 17 00:00:00 2001 From: John Marshall Date: Thu, 22 May 2025 21:06:03 +1200 Subject: [PATCH 1/4] Use correct type in mpileup_get_val() On little-endian hosts, `int` here caused incorrect results at positions beyond the range of int. On big-endian hosts, it caused incorrect results at all positions. --- plugins/vrfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/vrfs.c b/plugins/vrfs.c index 5e398957..1236fd66 100644 --- a/plugins/vrfs.c +++ b/plugins/vrfs.c @@ -347,7 +347,7 @@ static int batch_profile_run1(args_t *args, char *aln_fname) while ( (ret=mpileup_next(args->mplp))==1 ) { char *chr = mpileup_get_val(args->mplp,char*,CHROM); - hts_pos_t pos = mpileup_get_val(args->mplp,int,POS); + hts_pos_t pos = mpileup_get_val(args->mplp,hts_pos_t,POS); if ( !regidx_overlap(args->sites_idx, chr,pos,pos, args->sites_itr) ) { From 4e81fefc171c122f39c13cc8d69ab3a866080b79 Mon Sep 17 00:00:00 2001 From: John Marshall Date: Thu, 22 May 2025 21:24:44 +1200 Subject: [PATCH 2/4] Fix Makefile dependencies and clean mpileup2/*.o --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ffead3ec..c4a36d71 100644 --- a/Makefile +++ b/Makefile @@ -243,6 +243,7 @@ bam_sample_h = bam_sample.h $(htslib_sam_h) cigar_state_h = cigar_state.h $(htslib_hts_h) $(htslib_sam_h) read_consensus_h = read_consensus.h $(htslib_hts_h) $(htslib_sam_h) str_finder_h = str_finder.h utlist.h +mpileup2_mpileup_h = mpileup2/mpileup.h $(htslib_sam_h) str_finder.o: str_finder.c $(str_finder_h) utlist.h main.o: main.c $(htslib_hts_h) config.h version.h $(bcftools_h) @@ -287,14 +288,14 @@ cols.o: cols.c cols.h regidx.o: regidx.c $(htslib_hts_h) $(htslib_kstring_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) regidx.h consensus.o: consensus.c $(htslib_vcf_h) $(htslib_kstring_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_bgzf_h) regidx.h $(bcftools_h) rbuf.h $(filter_h) $(smpl_ilist_h) mpileup.o: mpileup.c $(htslib_sam_h) $(htslib_faidx_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) $(htslib_hts_os_h) regidx.h $(bcftools_h) $(bam2bcf_h) $(bam_sample_h) $(gvcf_h) -mpileup2/mpileup.o: mpileup2/mpileup.h mpileup2/mpileup.c $(htslib_sam_h) $(htslib_faidx_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) $(htslib_hts_os_h) $(bcftools_h) $(bam2bcf_h) $(bam_sample_h) +mpileup2/mpileup.o: mpileup2/mpileup.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_faidx_h) regidx.h $(mpileup2_mpileup_h) $(bam_sample_h) bam2bcf.o: bam2bcf.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_kstring_h) $(htslib_kfunc_h) $(bam2bcf_h) mw.h bam2bcf_indel.o: bam2bcf_indel.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_khash_str2int_h) $(bam2bcf_h) $(htslib_ksort_h) $(str_finder_h) bam2bcf_iaux.o: bam2bcf_iaux.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_khash_str2int_h) $(bcftools_h) $(bam2bcf_h) $(htslib_ksort_h) $(read_consensus_h) $(cigar_state_h) bam2bcf_edlib.o: bam2bcf_edlib.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_khash_str2int_h) $(bam2bcf_h) $(str_finder_h) $(htslib_ksort_h) edlib.h read_consensus.o: read_consensus.c $(read_consensus_h) $(cigar_state_h) $(bcftools_h) kheap.h bam_sample.o: bam_sample.c $(htslib_hts_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) $(khash_str2str_h) $(bam_sample_h) $(bcftools_h) -version.o: version.h version.c +version.o: version.c $(htslib_hts_h) $(bcftools_h) version.h hclust.o: hclust.c $(htslib_hts_h) $(htslib_kstring_h) $(bcftools_h) hclust.h HMM.o: HMM.c $(htslib_hts_h) HMM.h vcfbuf.o: vcfbuf.c $(htslib_vcf_h) $(htslib_vcfutils_h) $(htslib_hts_os_h) $(htslib_kbitset_h) $(bcftools_h) $(vcfbuf_h) rbuf.h @@ -359,7 +360,7 @@ install: $(PROGRAMS) $(PLUGINS) $(INSTALL_PROGRAM) plugins/*$(PLUGIN_EXT) $(DESTDIR)$(plugindir) clean: testclean clean-plugins - -rm -f gmon.out *.o *.a *~ $(PROGRAMS) version.h + -rm -f gmon.out *.o mpileup2/*.o *.a *~ $(PROGRAMS) version.h -rm -rf *.dSYM test/*.dSYM clean-plugins: From 713883b4a0a8bfa319c734a108b3c4ec5c2d66da Mon Sep 17 00:00:00 2001 From: John Marshall Date: Thu, 22 May 2025 22:05:35 +1200 Subject: [PATCH 3/4] Fix error reporting after closing files Calling bgzf_close() (and hts_close()) frees the file pointer, so the errcode field cannot be accessed afterwards. Report errors as per errno instead as is done in vcfconvert.c. Also report the right file pointer's errcode after bgzf_write() failure. --- reheader.c | 6 +++--- vcfconcat.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reheader.c b/reheader.c index 37e5d965..7b7bb062 100644 --- a/reheader.c +++ b/reheader.c @@ -418,7 +418,7 @@ static void reheader_vcf_gz(args_t *args) // Output all remaining data read with the header block if ( fp->block_length - skip_until > 0 ) { - if ( bgzf_write(bgzf_out, buffer+skip_until, fp->block_length-skip_until)<0 ) error("Error: %d\n",fp->errcode); + if ( bgzf_write(bgzf_out, buffer+skip_until, fp->block_length-skip_until)<0 ) error("Error: %d\n",bgzf_out->errcode); } if ( bgzf_flush(bgzf_out)<0 ) error("Error: %d\n",bgzf_out->errcode); @@ -434,8 +434,8 @@ static void reheader_vcf_gz(args_t *args) int count = bgzf_raw_write(bgzf_out, buf, nread); if (count != nread) error("Write failed, wrote %d instead of %d bytes.\n", count,(int)nread); } - if (bgzf_close(bgzf_out) < 0) error("Error closing %s: %d\n",args->output_fname ? args->output_fname : "-",bgzf_out->errcode); - if (hts_close(args->fp)) error("Error closing %s: %d\n",args->fname,fp->errcode); + if (bgzf_close(bgzf_out) < 0) error("Error closing %s: %s\n",args->output_fname ? args->output_fname : "-",strerror(errno)); + if (hts_close(args->fp)) error("Error closing %s: %s\n",args->fname,strerror(errno)); free(buf); } static void reheader_vcf(args_t *args) diff --git a/vcfconcat.c b/vcfconcat.c index 7b17ffe6..0c0b7678 100644 --- a/vcfconcat.c +++ b/vcfconcat.c @@ -919,7 +919,7 @@ static void naive_concat(args_t *args) // Output all non-header data that were read together with the header block if ( fp->block_length - nskip > 0 ) { - if ( bgzf_write(bgzf_out, (char *)fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("\nError: %d\n",fp->errcode); + if ( bgzf_write(bgzf_out, (char *)fp->uncompressed_block+nskip, fp->block_length-nskip)<0 ) error("\nError: %d\n",bgzf_out->errcode); } if ( bgzf_flush(bgzf_out)<0 ) error("\nError: %d\n",bgzf_out->errcode); @@ -952,7 +952,7 @@ static void naive_concat(args_t *args) } free(buf); free(tmp.s); - if (bgzf_close(bgzf_out) < 0) error("Error: %d\n",bgzf_out->errcode); + if (bgzf_close(bgzf_out) < 0) error("Error: %s\n",strerror(errno)); } static void usage(args_t *args) From 087c4095265c9e89a23cf836cf7d2831cb556fd4 Mon Sep 17 00:00:00 2001 From: John Marshall Date: Thu, 22 May 2025 22:20:48 +1200 Subject: [PATCH 4/4] Include for strncasecmp() declaration [minor] --- convert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/convert.c b/convert.c index ea51a4be..5ab39562 100644 --- a/convert.c +++ b/convert.c @@ -28,6 +28,7 @@ THE SOFTWARE. */ #include #include #include +#include #include #include #include