From 5c9d65d209349abe161b42a1fb24179eef60c05d Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Fri, 8 Sep 2006 00:33:40 +0000 Subject: [PATCH] catch a few more potential unchecked shared_ptr dereferences. --- alg/sequence.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/alg/sequence.cpp b/alg/sequence.cpp index 787f2a9..ae670c7 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -453,6 +453,11 @@ const std::list& Sequence::annotations() const Sequence Sequence::subseq(int start, int count) const { + if (!seq) { + Sequence new_seq; + return new_seq; + } + // there might be an off by one error with start+count > size() if ( count == npos || start+count > size()) { count = size()-start; @@ -578,11 +583,12 @@ std::string Sequence::get_sequence() const Sequence::const_reference Sequence::operator[](Sequence::size_type i) const { - return seq->at(i); + return at(i); } Sequence::const_reference Sequence::at(Sequence::size_type i) const { + if (!seq) throw std::out_of_range("empty sequence"); return seq->at(i); } @@ -906,6 +912,10 @@ Sequence::find_motif(const Sequence& a_motif) const void Sequence::motif_scan(std::string a_motif, std::vector * motif_match_starts) const { + // if there's no sequence we can't scan for it? + // should this throw an exception? + if (!seq) return; + std::string::const_iterator seq_c = seq->begin(); std::string::size_type seq_i; int motif_i, motif_len; -- 2.30.2