Boost logo

Boost-Commit :

From: droba_at_[hidden]
Date: 2008-06-17 17:58:59


Author: pavol_droba
Date: 2008-06-17 17:58:58 EDT (Tue, 17 Jun 2008)
New Revision: 46463
URL: http://svn.boost.org/trac/boost/changeset/46463

Log:
fixed the rle example crash

Text files modified:
   trunk/libs/algorithm/string/example/rle_example.cpp | 29 ++++++++++++++++++-----------
   1 files changed, 18 insertions(+), 11 deletions(-)

Modified: trunk/libs/algorithm/string/example/rle_example.cpp
==============================================================================
--- trunk/libs/algorithm/string/example/rle_example.cpp (original)
+++ trunk/libs/algorithm/string/example/rle_example.cpp 2008-06-17 17:58:58 EDT (Tue, 17 Jun 2008)
@@ -114,10 +114,13 @@
     result_type operator()( const ReplaceT& Replace ) const
     {
         SeqT r;
- r.push_back( repeat_mark<value_type>() );
- r.push_back( *(Replace.begin()) );
- r.push_back( value_type( Replace.size() ) );
-
+ if(!Replace.empty())
+ {
+ r.push_back( repeat_mark<value_type>() );
+ r.push_back( *(Replace.begin()) );
+ r.push_back( value_type( Replace.size() ) );
+ }
+
         return r;
     }
 };
@@ -183,14 +186,18 @@
     template< typename ReplaceT >
     result_type operator()( const ReplaceT& Replace ) const
     {
- // extract info
- typename ReplaceT::const_iterator It=Replace.begin();
-
- value_type Value=*(++It);
- value_type Repeat=*(++It);
-
         SeqT r;
- for( value_type Index=0; Index<Repeat; Index++ ) r.push_back( Value );
+
+ if(!Replace.empty())
+ {
+ // extract info
+ typename ReplaceT::const_iterator It=Replace.begin();
+
+ value_type Value=*(++It);
+ value_type Repeat=*(++It);
+
+ for( value_type Index=0; Index<Repeat; Index++ ) r.push_back( Value );
+ }
 
         return r;
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk