Boost logo

Boost-Commit :

From: Samuel.Krempp_at_[hidden]
Date: 2007-08-16 14:48:04


Author: samuel_krempp
Date: 2007-08-16 14:48:03 EDT (Thu, 16 Aug 2007)
New Revision: 38730
URL: http://svn.boost.org/trac/boost/changeset/38730

Log:
handle invalid format string (ends with %) without asserting,
closing ticket #493

Text files modified:
   trunk/boost/format/parsing.hpp | 15 +++++++++++++--
   1 files changed, 13 insertions(+), 2 deletions(-)

Modified: trunk/boost/format/parsing.hpp
==============================================================================
--- trunk/boost/format/parsing.hpp (original)
+++ trunk/boost/format/parsing.hpp 2007-08-16 14:48:03 EDT (Thu, 16 Aug 2007)
@@ -130,6 +130,12 @@
         bool in_brackets=false;
         Iter start0 = start;
         std::size_t fstring_size = last-start0+offset;
+
+ if(start>= last) { // empty directive : this is a trailing %
+ maybe_throw_exception(exceptions, start-start0 + offset, fstring_size);
+ return false;
+ }
+
         if(*start== const_or_not(fac).widen( '|')) {
             in_brackets=true;
             if( ++start >= last ) {
@@ -360,7 +366,10 @@
             if( i1+1 >= buf.size() ) {
                 if(exceptions & bad_format_string_bit)
                     boost::throw_exception(bad_format_string(i1, buf.size() )); // must not end in ".. %"
- else break; // stop there, ignore last '%'
+ else {
+ ++num_items;
+ break;
+ }
             }
             if(buf[i1+1] == buf[i1] ) {// escaped "%%"
                 i1+=2; continue;
@@ -429,8 +438,10 @@
             }
             BOOST_ASSERT( static_cast<unsigned int>(cur_item) < items_.size() || cur_item==0);
 
- if(i1!=i0)
+ if(i1!=i0) {
                 io::detail::append_string(piece, buf, i0, i1);
+ i0=i1;
+ }
             ++i1;
             it = buf.begin()+i1;
             bool parse_ok = io::detail::parse_printf_directive(


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