Boost logo

Boost :

From: René Bürgel (r.buergel_at_[hidden])
Date: 2007-03-05 11:05:51


Hi,

There is a bug in boost::format. It occurs, when format::parse is
called multiple times.
If there is a prefix before the first argument (%1%), it is prepended to
the new prefix.

I filed a minimal testcase to reproduce it. It works for Boost 1.33.1
and the CVS-Version.

#include <boost/format.hpp>
#include <iostream>

int main()
{
       boost::format Formatter;
       std::string Format1 = "sec = %1%";
       std::string Format2 = "min = %1%";

       Formatter.parse( Format1 );
       Formatter.parse( Format2 );

       Formatter.clear();
       Formatter % 3u; //just to write something

       std::cout << Formatter.str() << std::endl; //it prints "sec =
min = 3" instead of "min = 3"
}

A Patch against Boost 1.33.1 is here:

--- parsing.hpp 2006-10-20 08:36:42.000000000 +0100
+++ parsing2.hpp 2007-03-05 14:49:10.000000000 +0100
@@ -413,6 +413,7 @@
        // A: find upper_bound on num_items and allocates arrays
        int num_items = io::detail::upper_bound_from_fstring(buf,
arg_mark, fac, exceptions());
        make_or_reuse_data(num_items);
+ prefix_.resize( 0 );

        // B: Now the real parsing of the format string :
        num_items=0;

regards,
René Bürgel

-- 
Unicontrol Systemtechnik GmbH
OT Dittersbach
Sachsenburger Weg 34
09669 Frankenberg
 
Tel.: 03 72 06/ 88 73 - 12
Fax: 03 72 06/ 88 73 - 60
E-Mail: r.buergel_at_[hidden]
Internet: www.unicontrol.de
 
Unicontrol Systemtechnik GmbH
Geschäftsführer: Dipl.-Ing. Siegfried Heinze
Sitz der Gesellschaft: Frankenberg
Registergericht: Amtsgericht Chemnitz, HRB 15 475
 
Wichtiger Hinweis: Diese E-Mail und etwaige Anlagen können Betriebs- und Geschäftsgeheimnisse, dem Anwaltsgeheimnis unterliegende oder sonstige vertrauliche Informationen 
enthalten. Sollten Sie diese E-Mail irrtümlich erhalten haben, ist Ihnen der Status dieser E-Mail bekannt. Bitte benachrichtigen Sie uns in diesem Falle sofort durch 
Antwort-Mail und löschen Sie diese E-Mail nebst etwaigen Anlagen aus Ihrem System. Ebenso dürfen Sie diese E-Mail oder ihre Anlagen nicht kopieren oder an Dritte 
weitergeben. Vielen Dank!
 
Important Note: This e-mail and any attachments are confidential, may contain trade secrets and may well also be legally privileged or otherwise protected from disclosure. 
If you have received it in error, you are on notice of its status. Please notify us immediately by reply e-mail and then delete this e-mail and any attachment from your 
system. If you are not the intended recipient please understand that you must not copy this e-mail or any attachments or disclose the contents to any other person. Thank 
you.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk