Skip to content

Commit 0c238d1

Browse files
committed
Fix a bug in splitting Type=String FORMAT fields via -a and -m
Fixes #2476
1 parent ff97925 commit 0c238d1

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Changes affecting specific commands:
1212

1313
- Add new FORMAT/QM annotation, to be used with the new `bcftools +trio-dnm3 --use-ALM` model.
1414

15+
* bcftools norm
16+
17+
- Fix a bug in splitting Type=String FORMAT fields via -a and -m (#2476)
18+
1519
* bcftools +prune
1620

1721
- When pruning by window length in base pairs, one out-of-window record would

abuf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* The MIT License
22
3-
Copyright (c) 2021-2024 Genome Research Ltd.
3+
Copyright (c) 2021-2026 Genome Research Ltd.
44
55
Author: Petr Danecek <pd3@sanger.ac.uk>
66
@@ -630,8 +630,9 @@ static void _split_table_set_format(abuf_t *buf, bcf_fmt_t *fmt, merge_rule_t mo
630630
memset(buf->tmp2,0,nval1_dst*nsmpl);
631631
for (i=0; i<nsmpl; i++)
632632
{
633+
char *src = (char*)buf->tmp2 + nval1_dst*i;
633634
kstring_t dst;
634-
dst.l = 0; dst.m = nval1_dst; dst.s = (char*)buf->tmp2 + nval1_dst*i;
635+
dst.l = 0; dst.m = nval1_dst + 1; dst.s = src;
635636
kputc_('.',&dst);
636637
if ( star_allele ) kputsn_(",.",2,&dst);
637638
if ( len==BCF_VL_R )
@@ -641,6 +642,7 @@ static void _split_table_set_format(abuf_t *buf, bcf_fmt_t *fmt, merge_rule_t mo
641642
}
642643
copy_string_field(buf->tmp+nval1*i, iori+ioff, nval1, &dst, 0+ioff);
643644
if ( star_allele ) copy_string_field(".", 0, 1, &dst, 1+ioff);
645+
assert( src==dst.s ); // make sure copy_string_field() did not reallocate
644646
}
645647
ret = bcf_update_format(buf->out_hdr, out, tag, buf->tmp2, nval1_dst*nsmpl, type);
646648
}

test/test.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
run_test(\&test_vcf_norm,$opts,in=>'norm.symbolic.3',out=>'norm.symbolic.3.1.out',fai=>'norm.symbolic.3',args=>'');
305305
run_test(\&test_vcf_norm,$opts,in=>'norm',out=>'norm.out',fai=>'norm',args=>'-cx');
306306
run_test(\&test_vcf_norm,$opts,in=>'norm.split',out=>'norm.split.out',args=>'-m-');
307+
run_test(\&test_vcf_norm,$opts,in=>'norm.split',out=>'norm.split.1.out',args=>'-m- -a');
307308
run_test(\&test_vcf_norm,$opts,in=>'norm.split.2',out=>'norm.split.2.out',args=>'-m-');
308309
run_test(\&test_vcf_norm,$opts,in=>'norm.split.3',out=>'norm.split.3.out',args=>'-m- --force');
309310
run_test(\&test_vcf_norm,$opts,in=>'norm.split.4',out=>'norm.split.4.1.out',args=>'-m-');

0 commit comments

Comments
 (0)