Skip to content

Commit

Permalink
Fix vcf_var_has_info_key()'s key comparison
Browse files Browse the repository at this point in the history
Previously any key would be returned as being matched by the empty
"key=value" at the start of ";HRUN=3" (which is invalid VCF).

This resulted in a crash when e.g. lofreq_filter.c looking for "SB"
expected a value but in this case the returned sb_char was NULL.
Crash fixed by no longer returning a hit for "SB" in this case.

(Also convert a couple of previously missed legacy samtools API usages.)
  • Loading branch information
jmarshall committed Jun 12, 2020
1 parent 8206db2 commit 8cbc619
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lofreq/samutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ calc_read_alnerrprof(double *alnerrprof, unsigned long int *used_pos,

}
} /* for k */
/* calend not part of HTSlib API anymore? assert(pos == bam_calend(&b->core, bam_get_cigar(b))); FIXME correct assert? what if hard clipped? */
assert(pos == bam_endpos(b)); /* FIXME correct assert? what if hard clipped? */
if (qpos != qlen) {
LOG_FIXME("got qpos=%d and qlen=%d for cigar %s l_qseq %d\n", qpos, qlen, cigar_str_from_bam(b), b->core.l_qseq);
}
Expand Down Expand Up @@ -593,7 +593,7 @@ count_cigar_ops(int *counts, int **quals, const bam1_t *b,
}
} /* for k */

/* bam_calend not part of new HTSlib API assert(qpos == bam_calend(&b->core, bam_get_cigar(b))); FIXME correct assert? what if hard clipped? */
assert(qpos == bam_endpos(b)); /* FIXME correct assert? what if hard clipped? */
if (qpos != qlen) {
LOG_WARN("got qpos=%d and qlen=%d for cigar %s l_qseq %d in read %s\n", qpos, qlen, cigar_str_from_bam(b), b->core.l_qseq, bam_get_qname(b));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lofreq/vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ vcf_var_has_info_key(char **value, const var_t *var, const char *key) {
while (token) {
strsep(&info_ptr, field_delimiter);
/*fprintf(stderr, "token=%s key=%s\n", token, key);*/
if (0 == strncasecmp(key, token, MIN(strlen(token), strlen(key)))) {
if (strlen(token) >= strlen(key) && 0 == strncasecmp(key, token, strlen(key))) {
if (value) {
char *s = strchr(token, '=');
if (NULL != s) {
Expand Down

0 comments on commit 8cbc619

Please sign in to comment.