|
Boost Users : |
From: Mick Hollins (mick_at_[hidden])
Date: 2005-11-28 06:34:41
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.
2) Either way, what do people think is the best way forward?
thanks,
mick
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