From b362f29ca3eb96cd788ee84104acf255d6fa9582 Mon Sep 17 00:00:00 2001 From: Mikael Salson Date: Fri, 17 Jul 2015 10:05:43 +0200 Subject: [PATCH] fasta: When deleting the sequence explicitly put it at NULL This allows us to further test if the sequence has been deleted and avoids double free in case the FASTQ file is malformed. Test added --- algo/core/fasta.cpp | 4 +++- algo/tests/testTools.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/algo/core/fasta.cpp b/algo/core/fasta.cpp index af2061395..8f4a5203d 100644 --- a/algo/core/fasta.cpp +++ b/algo/core/fasta.cpp @@ -171,8 +171,10 @@ void OnlineFasta::next() { current.label.erase(); current.sequence.erase(); current.quality.erase(); - if (current.seq) + if (current.seq) { delete [] current.seq; + current.seq = NULL; + } if (hasNext()) { switch(line[0]) { diff --git a/algo/tests/testTools.cpp b/algo/tests/testTools.cpp index 43330b966..d6c70d736 100644 --- a/algo/tests/testTools.cpp +++ b/algo/tests/testTools.cpp @@ -163,6 +163,14 @@ void testFastaAddThrows() { } TAP_TEST(caught == true, TEST_FASTA_INVALID_FILE, ""); + caught = false; + try { + Fasta fa1("../../data/malformed7.fq"); + } catch(invalid_argument e) { + TAP_TEST(string(e.what()).find("Unexpected EOF") == 0, TEST_FASTA_INVALID_FILE, ""); + caught = true; + } + TAP_TEST(caught == true, TEST_FASTA_INVALID_FILE, ""); } void testSequenceOutputOperator() { -- GitLab