|
Boost Users : |
From: Richard Turrin (richt_at_[hidden])
Date: 2008-01-12 12:27:19
Hi,
I've encountered a bug with ireplace_all from the Boost String Algorithms library for version 1.35. If I pass a character array for the Format argument, the function ignores the null terminator and instead uses the entire array minus the last character to replace the occurrences of the Search string in the Input parameter. However, if I provide a pointer to a character array, the string replacement is done as expected.
When I stepped into the code, I came across the following lines (excerpt from /trunk/boost/range/as_literal.hpp):
template< class Char, std::size_t sz >
inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
{
return boost::make_iterator_range( arr, arr + sz - 1 );
}
There is no check for a null terminator. Nor did I find one after this function returned. I think the author here assumed that a caller would always pass in a character array of the right size.
I've attached a sample that demonstrates the problem. I performed the test in Visual Studio 2008. Let me know if you need more information. Thanks.
Rich Turrin
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