Boost logo

Boost Users :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2005-11-29 00:52:27


At 04:34 2005-11-28, Mick Hollins wrote:
>The following code causes a runtime assertion in VC 8.0:
>
> std::string l_param;
> std::string l_str = (boost::format("here is an empty string:
> %1%") % l_param).str();
>
>It passes an empty string argument to boost::format.
>The assert is inside the implementation of basic_string::append()
>and boils down to the fact that the implementation of boost::format
>ends up calling
>basic_string::append(const char *, size_type) with a null pointer,
>which causes
>basic_string::append to assert.
>
>The following sample code causes the same assertion without
>boost::format being involved:
>
> std::string l_str;
> const char *l_null = NULL;
> std::string::size_type l_size = 0;
> l_str.append(l_null, l_size); // causes an assert
>
>I have currently disabled the assertion by calling the following
>code before I do
>anything else:
>
> #if _MSC_VER >= 1400
> _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE);
> _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
> #endif
>
>which causes the asserts to simply emit a message to stderr rather than to pop
>up a message box, but I don't really want to disable VC 8.0's
>assertions across the board.
>
>My questions are:
>
>1) Is this considered to be a bug in boost::format or a case of VC
>8.0's runtime checks
> being overzealous? Personally I feel that calling append(null,
> 0) should be allowed
> and VC 8.0 is being too protective, but the copy of the C++
> standard I have suggests
> that VC 8.0 is correct.

I've been dismayed since I started using (std::)string
that (std::)string blah((char*)0); didn't work.
I'm not surprised that std::string::append suffers the same way.

>2) Either way, what do people think is the best way forward?
>
>thanks,
>mick
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users

Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
               "There oughta be a law"


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net