diff --git a/CHANGELOG.md b/CHANGELOG.md index d52cc31..9a5ccbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.18.4] +### Fixed +- Segfault on SAM-style tags without values in the FASTQ header. + ## [v0.18.3] ### Fixed - Bug causing segfault on unlikely RG SAM tags in FASTQ header comments. diff --git a/Makefile b/Makefile index 6e9e9c6..a7294c8 100644 --- a/Makefile +++ b/Makefile @@ -214,7 +214,6 @@ regression_test_parse_rg_fastq: fastcat done; rm -r test/test-tmp - .PHONY: regression_test_parse_rg_bam regression_test_parse_rg_bam: bamstats if [ -d test/test-tmp ]; then rm -r test/test-tmp; fi @@ -233,6 +232,10 @@ regression_test_parse_rd_fastq: fastcat if [ -d test/test-tmp ]; then rm -r test/test-tmp; fi mkdir test/test-tmp && \ cd test/test-tmp && \ - ../../fastcat ../parse_rd/RD-first-tag-and-no-RG.fastq -i rd > /dev/null && \ - grep -q dummy_run_id rd + for i in ../parse_rd/*.fastq; do \ + echo $$i; \ + ../../fastcat $$i --histograms hist -i rd > /dev/null; \ + diff rd $$i.runids; \ + rm -rf hist rg; \ + done; rm -r test/test-tmp diff --git a/src/fastqcomments.c b/src/fastqcomments.c index 6086693..686334b 100644 --- a/src/fastqcomments.c +++ b/src/fastqcomments.c @@ -87,6 +87,9 @@ read_meta parse_read_meta(kstring_t comment) { key = strtok_r(pch, ":", &p2); keytype = strtok_r(NULL, ":", &p2); value = strtok_r(NULL, "", &p2); + // we allow empty tags (e.g. 'RG:Z:'); in this case, `keytype` will be + // non-null, but `value` will be null; we set it to "" + if (keytype != NULL && value == NULL) value = ""; } else { // split words on `=` @@ -96,7 +99,7 @@ read_meta parse_read_meta(kstring_t comment) { } // if there was no delimiter in the word, value will be NULL --> add word to `rest` - if (value == NULL && !sam_tags) { + if (value == NULL) { ksprintf_with_opt_delim(meta->rest, " ", "%s", key); } else { if (!strcmp(key, "runid") || !strcmp(key, "RD")) { diff --git a/src/version.h b/src/version.h index bc292fc..5493bd7 100644 --- a/src/version.h +++ b/src/version.h @@ -1,2 +1,2 @@ -const char *argp_program_version = "0.18.3"; +const char *argp_program_version = "0.18.4"; diff --git a/test/parse_rd/RD-first-tag-and-no-RG.fastq b/test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq similarity index 100% rename from test/parse_rd/RD-first-tag-and-no-RG.fastq rename to test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq diff --git a/test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq.runids b/test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq.runids new file mode 100644 index 0000000..29e0b09 --- /dev/null +++ b/test/parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq.runids @@ -0,0 +1,2 @@ +filename run_id count +../parse_rd/RD-first-tag-and-no-RG-CW-4285.fastq dummy_run_id 1 diff --git a/test/parse_rd/empty-RD-CW-4299.fastq b/test/parse_rd/empty-RD-CW-4299.fastq new file mode 100644 index 0000000..7b3ca34 --- /dev/null +++ b/test/parse_rd/empty-RD-CW-4299.fastq @@ -0,0 +1,4 @@ +@9ae4818c-61e9-4011-bf40-ca5721922da4 RD:Z: +AAAAAAAAAAAAAAAAAA ++ +AAAAAAAAAAAAAAAAAA diff --git a/test/parse_rd/empty-RD-CW-4299.fastq.runids b/test/parse_rd/empty-RD-CW-4299.fastq.runids new file mode 100644 index 0000000..24ae33a --- /dev/null +++ b/test/parse_rd/empty-RD-CW-4299.fastq.runids @@ -0,0 +1,2 @@ +filename run_id count +../parse_rd/empty-RD-CW-4299.fastq 1