catch possible segfault with get_sequence()
authorDiane Trout <diane@caltech.edu>
Tue, 19 Sep 2006 20:45:50 +0000 (20:45 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 19 Sep 2006 20:45:50 +0000 (20:45 +0000)
alg/sequence.cpp
alg/test/test_sequence.cpp

index 92a7edca08fd7d45ed36905b86def2121b330f23..845a01617016dd17dfcf7e8c96bc55d0fa43acd8 100644 (file)
@@ -603,7 +603,10 @@ void Sequence::set_sequence(const std::string& s)
 
 std::string Sequence::get_sequence() const
 {
-  return *seq;
+  if (seq) 
+    return *seq;
+  else
+    return std::string();
 }
 
 Sequence::const_reference Sequence::operator[](Sequence::size_type i) const
index 3a2b9db428b8419b809b46c6315a3cd2c10e89cf..c588555e9be18e9f9eecec5e858d70245820c9cd 100644 (file)
@@ -17,6 +17,13 @@ namespace fs=boost::filesystem;
 
 using namespace std;
 
+BOOST_AUTO_TEST_CASE( sequence_get_sequence )
+{
+       Sequence s;
+       // make sure that retrieving the sequence doesn't throw an error
+       BOOST_CHECK_EQUAL(s.get_sequence(), std::string() );
+}
+
 //! when we try to load a missing file, do we get an error?
 BOOST_AUTO_TEST_CASE( sequence_load_exception )
 {