catch a few more potential unchecked shared_ptr dereferences.
authorDiane Trout <diane@caltech.edu>
Fri, 8 Sep 2006 00:33:40 +0000 (00:33 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 8 Sep 2006 00:33:40 +0000 (00:33 +0000)
alg/sequence.cpp

index 787f2a9dae0849c13c9224db1f5bfa9549344ba7..ae670c7748da38926add1069f2ce043a15ec3fad 100644 (file)
@@ -453,6 +453,11 @@ const std::list<annot>& 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<int> * 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;