boost::format with empty string...
Using MS Visual C++ 2005, Express Edition, the following snippet causes an
assertion failure due to a NULL pointer in the bowels of boost::format:
boost::format f( "test %1%\n" );
f % "";
I traced it down to boost/format/feed_args.hpp:
template
Hi,
I assume you're using the current official release.
I believe the problem is already fixed in 1.34 in CVS.
Thanks
Shams
----- Original Message -----
From: "Early Ehlinger"
Using MS Visual C++ 2005, Express Edition, the following snippet causes an assertion failure due to a NULL pointer in the bowels of boost::format:
boost::format f( "test %1%\n" ); f % "";
I traced it down to boost/format/feed_args.hpp:
template
void mk_str( std::basic_string & res, const Ch * beg, typename std::basic_string ::size_type size, std::streamsize w, const Ch fill_char, std::ios_base::fmtflags f, const Ch prefix_space, // 0 if no space-padding bool center) // applies centered/left/right padding to the string [beg, beg+size[ // Effects : the result is placed in res. { typedef typename std::basic_string ::size_type size_type; res.resize(0); if( ( w<=0 || static_cast (w) <=size)) { // no need to pad. res.reserve(size + !!prefix_space); if(prefix_space) res.append(1, prefix_space); res.append(beg, size); <<--- crashes, because beg==NULL and size==0 ... My suggested fix looks like this: template void mk_str( std::basic_string & res, const Ch * beg, typename std::basic_string ::size_type size, std::streamsize w, const Ch fill_char, std::ios_base::fmtflags f, const Ch prefix_space, // 0 if no space-padding bool center) // applies centered/left/right padding to the string [beg, beg+size[ // Effects : the result is placed in res. { typedef typename std::basic_string ::size_type size_type; res.resize(0); if(size && ( w<=0 || static_cast (w) <=size)) { // no need to pad. res.reserve(size + !!prefix_space); if(prefix_space) res.append(1, prefix_space); res.append(beg, size); } else { std::streamsize n=static_caststd::streamsize(w-size-!!prefix_space); std::streamsize n_after = 0, n_before = 0; res.reserve(w); // allocate once for the 2 inserts if(center) n_after = n/2, n_before = n - n_after; else if(f & std::ios_base::left) n_after = n; else n_before = n; // now make the res string : if(n_before) res.append(n_before, fill_char); if(prefix_space) res.append(1, prefix_space); if ( size ) res.append(beg, size); if(n_after) res.append(n_after, fill_char); } } // -mk_str(..) -- Early Ehlinger, President, ResPower, Inc.
I should've mentioned that. Yes - 1.33.1. -- Early Shams wrote:
Hi,
I assume you're using the current official release. I believe the problem is already fixed in 1.34 in CVS.
Thanks Shams
----- Original Message ----- From: "Early Ehlinger"
Newsgroups: gmane.comp.lib.boost.user To: Sent: Thursday, March 29, 2007 4:46 AM Subject: boost::format with empty string... Using MS Visual C++ 2005, Express Edition, the following snippet causes an assertion failure due to a NULL pointer in the bowels of boost::format:
boost::format f( "test %1%\n" ); f % "";
I traced it down to boost/format/feed_args.hpp:
template
void mk_str( std::basic_string & res, const Ch * beg, typename std::basic_string ::size_type size, std::streamsize w, const Ch fill_char, std::ios_base::fmtflags f, const Ch prefix_space, // 0 if no space-padding bool center) // applies centered/left/right padding to the string [beg, beg+size[ // Effects : the result is placed in res. { typedef typename std::basic_string ::size_type size_type; res.resize(0); if( ( w<=0 || static_cast (w) <=size)) { // no need to pad. res.reserve(size + !!prefix_space); if(prefix_space) res.append(1, prefix_space); res.append(beg, size); <<--- crashes, because beg==NULL and size==0 ... My suggested fix looks like this: template void mk_str( std::basic_string & res, const Ch * beg, typename std::basic_string ::size_type size, std::streamsize w, const Ch fill_char, std::ios_base::fmtflags f, const Ch prefix_space, // 0 if no space-padding bool center) // applies centered/left/right padding to the string [beg, beg+size[ // Effects : the result is placed in res. { typedef typename std::basic_string ::size_type size_type; res.resize(0); if(size && ( w<=0 || static_cast (w) <=size)) { // no need to pad. res.reserve(size + !!prefix_space); if(prefix_space) res.append(1, prefix_space); res.append(beg, size); } else { std::streamsize n=static_caststd::streamsize(w-size-!!prefix_space); std::streamsize n_after = 0, n_before = 0; res.reserve(w); // allocate once for the 2 inserts if(center) n_after = n/2, n_before = n - n_after; else if(f & std::ios_base::left) n_after = n; else n_before = n; // now make the res string : if(n_before) res.append(n_before, fill_char); if(prefix_space) res.append(1, prefix_space); if ( size ) res.append(beg, size); if(n_after) res.append(n_after, fill_char); } } // -mk_str(..) -- Early Ehlinger, President, ResPower, Inc.
participants (2)
-
Early Ehlinger
-
Shams