diff --git a/CHANGES.md b/CHANGES.md index a19e276..f3b69e8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,10 @@ * Making species and assembly required commandline arguments in the estep +## 1.13.15 + +* Add checks to sam_iter_next to ensure result is checked for errors + ## 1.13.14 * Fix array length index, check loop length and error messages related to 1.13.13. diff --git a/Makefile b/Makefile index b40091c..42279aa 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CAVEMAN_VERSION=1.13.14 +CAVEMAN_VERSION=1.13.15 TEST_REF?="" #Compiler diff --git a/src/bam_access.c b/src/bam_access.c index 074281c..759461f 100644 --- a/src/bam_access.c +++ b/src/bam_access.c @@ -408,9 +408,7 @@ file_holder *bam_access_get_by_position_counts_stranded(char *norm_file, char *c check(res==0,"Error running pileup callback"); }//End of while we have pileup reads } - if(result != -1){ - fprintf(stderr,"SAMTOOLS ERROR %d\n",result); - } + check(result >= -1, "Error detected (%d) when trying to iterate through region.",result); bam_plp_push(buf,0); // finalize pileup sam_itr_destroy(iter); //Now for the pileup method @@ -1243,7 +1241,7 @@ List *bam_access_get_sorted_reads_at_this_pos(char *chr_name, uint32_t start, ui } }//End of while iterator to populate pileup - + check(result >= -1, "Error detected (%d) when trying to iterate through region.",result); sam_itr_destroy(iter); bam_plp_push(buf,0); // finalize pileup @@ -1336,10 +1334,17 @@ int bam_access_get_count_with_bam(char *chr_name, uint32_t start, uint32_t stop, counter++; }//End of iteration through reads in this region + check(result >= -1, "Error detected (%d) when trying to iterate through region.",result); sam_itr_destroy(iter); bam_destroy1(b); free(region); return counter; + +error: + if(iter) sam_itr_destroy(iter); + if(b) bam_destroy1(b); + if(region) free(region); + return -1; } void bam_access_include_sw(int inc){ diff --git a/src/split.c b/src/split.c index 4429917..2d91828 100644 --- a/src/split.c +++ b/src/split.c @@ -278,6 +278,7 @@ int split_main(int argc, char *argv[]){ while(curr_n_pos<=curr_t_pos && iter_n_status>=0 && iter_t_status>=0 && rd_count<=max_read_count){ //While the positions aren't equal and tumour has reads left. Normal jumps ahead iter_n_status = sam_itr_next(sf_norm,iter_norm,norm_read); + check(iter_n_status>=-1,"Error detected (%d) when trying to iterate through region.",iter_n_status); curr_n_pos = norm_read->core.pos; if(iter_n_status>=0 && bam_access_check_bam_flags(norm_read) == 1 && ignore_reg_access_get_ign_reg_overlap(curr_n_pos,ignore_regs,ignore_reg_count) == NULL){ rd_count++; @@ -286,6 +287,7 @@ int split_main(int argc, char *argv[]){ while(curr_t_pos<=curr_n_pos && iter_t_status>=0 && iter_n_status>=0){ //While the positions aren't equal and normal has reads left iter_t_status = sam_itr_next(sf_tum,iter_tum,tum_read); + check(iter_t_status>=-1,"Error detected (%d) when trying to iterate through region.",iter_t_status); curr_t_pos = tum_read->core.pos; if(iter_t_status>=0 && bam_access_check_bam_flags(tum_read) == 1 && ignore_reg_access_get_ign_reg_overlap(curr_t_pos,ignore_regs,ignore_reg_count) == NULL){ rd_count++; @@ -296,6 +298,7 @@ int split_main(int argc, char *argv[]){ if(iter_n_status<0 && iter_t_status>=0){ //No more normal reads while(iter_t_status>=0 && rd_count<=max_read_count){ iter_t_status = sam_itr_next(sf_tum,iter_tum,tum_read); + check(iter_t_status>=-1,"Error detected (%d) when trying to iterate through region.",iter_t_status); curr_t_pos = tum_read->core.pos; if(iter_t_status>=0 && bam_access_check_bam_flags(tum_read) == 1 && ignore_reg_access_get_ign_reg_overlap(curr_t_pos,ignore_regs,ignore_reg_count) == NULL){ rd_count++; @@ -306,6 +309,7 @@ int split_main(int argc, char *argv[]){ if(iter_t_status<0 && iter_n_status>=0){ //No more tumour reads while(iter_n_status>=0 && rd_count<=max_read_count){ iter_n_status = sam_itr_next(sf_norm,iter_norm,norm_read); + check(iter_n_status>=-1,"Error detected (%d) when trying to iterate through region.",iter_n_status); curr_n_pos = norm_read->core.pos; if(iter_n_status>=0 && bam_access_check_bam_flags(norm_read) == 1 && ignore_reg_access_get_ign_reg_overlap(curr_n_pos,ignore_regs,ignore_reg_count) == NULL){ rd_count++;