Skip to content

Commit 0039c20

Browse files
sirus20x6pd3
authored andcommitted
Fix 10 assorted medium-severity bugs across multiple files
- vcffilter.c: Change max_qual from int to float to avoid truncation of fractional QUAL values - vcfview.c: Guard args->ac[1] access with n_allele>=2 check for ALLELE_ALT1 filtering to prevent out-of-bounds on REF-only sites - convert.c: Invert bcf_gt_is_phased() condition in process_gt_to_hap and process_gt_to_hap2 ('*' marks unphased, not phased) - convert.c: Use gt_id instead of fmt->id for GT header existence check in process_pbinom - convert.c: Fix off-by-one in allele bounds check (al >= n_allele, not al > n_allele) since allele index is 0-based - dist.c: Fix double-counting in dist_insert_n; dist_insert already increments nvalues by 1, so add cnt-1 not cnt - bin.c: Prevent bin_get_idx from returning -1 when value is below first bin boundary - read_consensus.c: Fix loop condition from j<dfreq[i].len[j] to dfreq[i].len[j] (nonzero check) matching the pattern used elsewhere - gff.c: Fix Mt_rRNA returning GF_MT_tRNA instead of GF_MT_rRNA (copy-paste error) - gff.c: Fix strncmp length for "lncRNA" from 7 to 6
1 parent 8cd70c9 commit 0039c20

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

bin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ int bin_get_idx(bin_t *bin, float value)
101101
else return i;
102102
}
103103
if ( bin->bins[imax] <= value ) return imax;
104-
return imin - 1;
104+
return imin > 0 ? imin - 1 : 0;
105105
}
106106

convert.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,10 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int
10141014
else
10151015
{
10161016
kputw(bcf_gt_allele(ptr[0]),str);
1017-
if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
1017+
if ( !bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
10181018
str->s[str->l++] = ' ';
10191019
kputw(bcf_gt_allele(ptr[1]),str);
1020-
if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
1020+
if ( !bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
10211021
str->s[str->l++] = ' ';
10221022
}
10231023
}
@@ -1140,10 +1140,10 @@ static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int
11401140
else
11411141
{
11421142
kputw(bcf_gt_allele(ptr[0]),str);
1143-
if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
1143+
if ( !bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
11441144
str->s[str->l++] = ' ';
11451145
kputw(bcf_gt_allele(ptr[1]),str);
1146-
if ( bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
1146+
if ( !bcf_gt_is_phased(ptr[1]) ) str->s[str->l++] = '*';
11471147
str->s[str->l++] = ' ';
11481148
}
11491149
}
@@ -1250,7 +1250,7 @@ static void process_pbinom(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa
12501250

12511251
// Check that the first field is GT
12521252
int gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT");
1253-
if ( !bcf_hdr_idinfo_exists(convert->header, BCF_HL_FMT, fmt->id) ) error("Error: FORMAT/GT is not defined in the header\n");
1253+
if ( !bcf_hdr_idinfo_exists(convert->header, BCF_HL_FMT, gt_id) ) error("Error: FORMAT/GT is not defined in the header\n");
12541254
for (i=0; i<(int)line->n_fmt; i++)
12551255
if ( line->d.fmt[i].id==gt_id ) { fmt->usr = &line->d.fmt[i]; break; } // it should always be first according to VCF spec, but...
12561256

@@ -1268,7 +1268,7 @@ static void process_pbinom(convert_t *convert, bcf1_t *line, fmt_t *fmt, int isa
12681268
{
12691269
if ( bcf_gt_is_missing(gt[i]) || gt[i] == bcf_int8_vector_end ) goto invalid;
12701270
int al = bcf_gt_allele(gt[i]);
1271-
if ( al > line->n_allele || al >= fmt->fmt->n ) goto invalid;
1271+
if ( al >= line->n_allele || al >= fmt->fmt->n ) goto invalid;
12721272

12731273
#define BRANCH(type_t, convert, missing, vector_end) { \
12741274
type_t val = convert(&fmt->fmt->p[(al + isample*fmt->fmt->n)*sizeof(type_t)]); \

dist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ uint32_t dist_insert_n(dist_t *dist, uint32_t value, uint32_t cnt)
9797
if ( !cnt ) return 0;
9898
int ibin = dist_insert(dist, value);
9999
dist->bins[ibin] += cnt - 1;
100-
dist->nvalues += cnt;
100+
dist->nvalues += cnt - 1;
101101
return ibin;
102102
}
103103

gff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ static inline int gff_parse_biotype(char *line)
312312
case 'M':
313313
if ( !strncmp(line,"Mt_tRNA_pseudogene",18) ) return GF_MT_tRNA_PSEUDOGENE;
314314
else if ( !strncasecmp(line,"Mt_tRNA",7) ) return GF_MT_tRNA;
315-
else if ( !strncasecmp(line,"Mt_rRNA",7) ) return GF_MT_tRNA;
315+
else if ( !strncasecmp(line,"Mt_rRNA",7) ) return GF_MT_rRNA;
316316
else if ( !strncasecmp(line,"MRNA",4) ) return GF_PROTEIN_CODING;
317317
break;
318318
case 'l':
319319
if ( !strncmp(line,"lincRNA",7) ) return GF_lincRNA;
320-
if ( !strncmp(line,"lncRNA",7) ) return GF_lncRNA;
320+
if ( !strncmp(line,"lncRNA",6) ) return GF_lncRNA;
321321
break;
322322
case 'm':
323323
if ( !strncmp(line,"macro_lncRNA",12) ) return GF_macro_lncRNA;

read_consensus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static int select_candidate_variants(read_cns_t *rcns, const char *ref)
489489
// Find the longest deletion at the query position
490490
i = rcns->pos - rcns->beg;
491491
rcns->max_del = 0;
492-
for (j=0; j<NI && j<dfreq[i].len[j]; j++)
492+
for (j=0; j<NI && dfreq[i].len[j]; j++)
493493
{
494494
if ( rcns->max_del < dfreq[i].len[j] ) rcns->max_del = dfreq[i].len[j];
495495
}

vcffilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void buffered_filters(args_t *args, bcf1_t *line)
310310
if ( k_flush || !line )
311311
{
312312
// Select the best indel from the cluster of k_flush indels
313-
int k = 0, max_ac = -1, imax_ac = -1, max_qual = -1, imax_qual = -1;
313+
int k = 0, max_ac = -1, imax_ac = -1, imax_qual = -1; float max_qual = -1;
314314
for (i=-1; rbuf_next(&args->rbuf,&i) && k<k_flush; )
315315
{
316316
k++;

vcfview.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,15 @@ int subset_vcf(args_t *args, bcf1_t *line)
415415
{
416416
if (args->min_ac_type == ALLELE_NONREF && args->min_ac>non_ref_ac) return 0; // min AC
417417
else if (args->min_ac_type == ALLELE_MINOR && args->min_ac>minor_ac) return 0; // min minor AC
418-
else if (args->min_ac_type == ALLELE_ALT1 && args->min_ac>args->ac[1]) return 0; // min 1st alternate AC
418+
else if (args->min_ac_type == ALLELE_ALT1 && (line->n_allele<2 || args->min_ac>args->ac[1])) return 0; // min 1st alternate AC
419419
else if (args->min_ac_type == ALLELE_MAJOR && args->min_ac > major_ac) return 0; // min major AC
420420
else if (args->min_ac_type == ALLELE_NONMAJOR && args->min_ac > an-major_ac) return 0; // min non-major AC
421421
}
422422
if (args->max_ac!=-1)
423423
{
424424
if (args->max_ac_type == ALLELE_NONREF && args->max_ac<non_ref_ac) return 0; // max AC
425425
else if (args->max_ac_type == ALLELE_MINOR && args->max_ac<minor_ac) return 0; // max minor AC
426-
else if (args->max_ac_type == ALLELE_ALT1 && args->max_ac<args->ac[1]) return 0; // max 1st alternate AC
426+
else if (args->max_ac_type == ALLELE_ALT1 && line->n_allele>=2 && args->max_ac<args->ac[1]) return 0; // max 1st alternate AC
427427
else if (args->max_ac_type == ALLELE_MAJOR && args->max_ac < major_ac) return 0; // max major AC
428428
else if (args->max_ac_type == ALLELE_NONMAJOR && args->max_ac < an-major_ac) return 0; // max non-major AC
429429
}
@@ -432,7 +432,7 @@ int subset_vcf(args_t *args, bcf1_t *line)
432432
if (an == 0) return 0; // freq not defined, skip site
433433
if (args->min_af_type == ALLELE_NONREF && args->min_af>non_ref_ac/(double)an) return 0; // min AF
434434
else if (args->min_af_type == ALLELE_MINOR && args->min_af>minor_ac/(double)an) return 0; // min minor AF
435-
else if (args->min_af_type == ALLELE_ALT1 && args->min_af>args->ac[1]/(double)an) return 0; // min 1st alternate AF
435+
else if (args->min_af_type == ALLELE_ALT1 && (line->n_allele<2 || args->min_af>args->ac[1]/(double)an)) return 0; // min 1st alternate AF
436436
else if (args->min_af_type == ALLELE_MAJOR && args->min_af > major_ac/(double)an) return 0; // min major AF
437437
else if (args->min_af_type == ALLELE_NONMAJOR && args->min_af > (an-major_ac)/(double)an) return 0; // min non-major AF
438438
}
@@ -441,7 +441,7 @@ int subset_vcf(args_t *args, bcf1_t *line)
441441
if (an == 0) return 0; // freq not defined, skip site
442442
if (args->max_af_type == ALLELE_NONREF && args->max_af<non_ref_ac/(double)an) return 0; // max AF
443443
else if (args->max_af_type == ALLELE_MINOR && args->max_af<minor_ac/(double)an) return 0; // max minor AF
444-
else if (args->max_af_type == ALLELE_ALT1 && args->max_af<args->ac[1]/(double)an) return 0; // max 1st alternate AF
444+
else if (args->max_af_type == ALLELE_ALT1 && line->n_allele>=2 && args->max_af<args->ac[1]/(double)an) return 0; // max 1st alternate AF
445445
else if (args->max_af_type == ALLELE_MAJOR && args->max_af < major_ac/(double)an) return 0; // max major AF
446446
else if (args->max_af_type == ALLELE_NONMAJOR && args->max_af < (an-major_ac)/(double)an) return 0; // max non-major AF
447447
}

0 commit comments

Comments
 (0)